ECPrivateKey
public class ECPrivateKey : CustomStringConvertible
An Elliptic Curve private key
-
Creates a private key
Throws
An exception if s < 1 or s >= the domain orderDeclaration
Swift
public init(domain: Domain, s: BInt) throwsParameters
domainThe domain the key belongs to
sThe secret key value
-
Creates a private key from its DER encoding
Throws
An exception if the DER encoding is wrongDeclaration
Swift
public convenience init(der: Bytes, pkcs8: Bool = false) throwsParameters
derThe DER encoding of the key
pkcs8true if the encoding is in PKCS#8 format - else false
-
Creates a private key from its PEM encoding. The PEM type is either ‘PRIVATE KEY’ meaning the format is PKCS#8, or it is ‘EC PRIVATE KEY’ meaning the format is not PKCS#8
Throws
An exception if the PEM encoding is wrongDeclaration
Swift
public convenience init(pem: String) throwsParameters
pemThe PEM encoding of the key
-
Creates a private key from its encrypted DER encoding. The key must have been encrypted with one of the ciphers AES-128, AES-192 or AES-256 in CBC mode.
Throws
An exception if the DER encoding is wrongParameters
derThe DER encoding of the encrypted key
passwordThe password
-
Creates a private key from its encrypted PEM encoding. The key must have been encrypted with one of the ciphers AES-128, AES-192 or AES-256 in CBC mode. The PEM type is ‘ENCRYPTED PRIVATE KEY’
Throws
An exception if the PEM encoding is wrongDeclaration
Swift
public convenience init(pem: String, password: Bytes) throwsParameters
pemThe PEM encoding of the encrypted key
passwordThe password
-
The domain the key belongs to
Declaration
Swift
public let domain: Domain -
The private value - a positive integer
Declaration
Swift
public let s: BInt
-
The ASN1 encoding of self
Declaration
Swift
public var asn1: ASN1 { get } -
The DER encoding of self
Declaration
Swift
public var der: Bytes { get } -
The PEM base 64 encoding of self
Declaration
Swift
public var pem: String { get } -
The DER encoding of self in PKCS#8 format
Declaration
Swift
public var derPkcs8: Bytes { get } -
The PEM base 64 encoding of self in PKCS#8 format
Declaration
Swift
public var pemPkcs8: String { get } -
A textual representation of the ASN1 encoding of self
Declaration
Swift
public var description: String { get }
-
Computes the password based encrypted encoding of self in DER format, using cipher block mode = CBC, iteration count = 2048 and salt = 8 random bytes
Parameters
passwordThe password
cipherthe AES cipher to use
Return Value
The DER encrypted encoding
-
Computes the password based encrypted encoding of self in PEM format, using cipher block mode = CBC, iteration count = 2048 and salt = 8 random bytes
Parameters
passwordThe password
cipherthe AES cipher to use
Return Value
The PEM encrypted encoding
-
Signs a byte array message with ECDSA
Declaration
Swift
public func sign(msg: Bytes, deterministic: Bool = false) -> ECSignatureParameters
msgThe message to sign
deterministicIf true generate a deterministic signature according to RFC-6979, if false generate a non-deterministic signature - false is default
Return Value
The signature
-
Signs a Data message with ECDSA
Declaration
Swift
public func sign(msg: Data, deterministic: Bool = false) -> ECSignatureParameters
msgThe message to sign
deterministicIf true generate a deterministic signature according to RFC-6979, if false generate a non-deterministic signature - false is default
Return Value
The signature
-
Decrypts a byte array message with ECIES
Throws
An exception if the message authentication fails or the message is too shortDeclaration
Parameters
msgThe bytes to decrypt
cipherThe AES cipher to use
modeThe block mode to use - GCM is default
Return Value
The decrypted message
-
Decrypts a Data message with ECIES
Throws
An exception if the message authentication fails or the message is too shortDeclaration
Parameters
msgThe data to decrypt
cipherThe AES cipher to use
modeThe block mode to use - GCM is default
Return Value
The decrypted message
-
Constructs a shared secret key using Diffie-Hellman key agreement - please refer [SEC 1] section 3.3.1
Throws
An exception if this and pubKey do not belong to the same domain or length is negativeDeclaration
Swift
public func keyAgreement(pubKey: ECPublicKey, length: Int, md: MessageDigestAlgorithm, sharedInfo: Bytes, cofactor: Bool = false) throws -> BytesParameters
pubKeyThe other party’s public key
lengthThe required length of the shared secret
mdThe message digest algorithm to use
sharedInfoInformation shared with the other party
cofactorUse cofactor version - false is default
Return Value
A byte array which is the shared secret key
ECPrivateKey Class Reference