ECPrivateKey

public class ECPrivateKey : CustomStringConvertible

An Elliptic Curve private key

Initializers

  • Creates a private key

    Throws

    An exception if s < 1 or s >= the domain order

    Declaration

    Swift

    public init(domain: Domain, s: BInt) throws

    Parameters

    domain

    The domain the key belongs to

    s

    The secret key value

  • Creates a private key from its DER encoding

    Throws

    An exception if the DER encoding is wrong

    Declaration

    Swift

    public convenience init(der: Bytes, pkcs8: Bool = false) throws

    Parameters

    der

    The DER encoding of the key

    pkcs8

    true 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 wrong

    Declaration

    Swift

    public convenience init(pem: String) throws

    Parameters

    pem

    The 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 wrong

    Declaration

    Swift

    public convenience init(der: Bytes, password: Bytes) throws

    Parameters

    der

    The DER encoding of the encrypted key

    password

    The 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 wrong

    Declaration

    Swift

    public convenience init(pem: String, password: Bytes) throws

    Parameters

    pem

    The PEM encoding of the encrypted key

    password

    The password

Stored Properties

  • The domain the key belongs to

    Declaration

    Swift

    public let domain: Domain
  • s

    The private value - a positive integer

    Declaration

    Swift

    public let s: BInt

Computed Properties

  • The ASN1 encoding of self

    Declaration

    Swift

    public var asn1: ASN1 { get }
  • der

    The DER encoding of self

    Declaration

    Swift

    public var der: Bytes { get }
  • pem

    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 }

Instance Methods

  • Computes the password based encrypted encoding of self in DER format,
    using cipher block mode = CBC, iteration count = 2048 and salt = 8 random bytes

    Declaration

    Swift

    public func derEncrypted(password: Bytes, cipher: AESCipher) -> Bytes

    Parameters

    password

    The password

    cipher

    the 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

    Declaration

    Swift

    public func pemEncrypted(password: Bytes, cipher: AESCipher) -> String

    Parameters

    password

    The password

    cipher

    the 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) -> ECSignature

    Parameters

    msg

    The message to sign

    deterministic

    If 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) -> ECSignature

    Parameters

    msg

    The message to sign

    deterministic

    If 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 short

    Declaration

    Swift

    public func decrypt(msg: Bytes, cipher: AESCipher, mode: BlockMode = .GCM) throws -> Bytes

    Parameters

    msg

    The bytes to decrypt

    cipher

    The AES cipher to use

    mode

    The 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 short

    Declaration

    Swift

    public func decrypt(msg: Data, cipher: AESCipher, mode: BlockMode = .GCM) throws -> Data

    Parameters

    msg

    The data to decrypt

    cipher

    The AES cipher to use

    mode

    The 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 negative

    Declaration

    Swift

    public func keyAgreement(pubKey: ECPublicKey, length: Int, md: MessageDigestAlgorithm, sharedInfo: Bytes, cofactor: Bool = false) throws -> Bytes

    Parameters

    pubKey

    The other party’s public key

    length

    The required length of the shared secret

    md

    The message digest algorithm to use

    sharedInfo

    Information shared with the other party

    cofactor

    Use cofactor version - false is default

    Return Value

    A byte array which is the shared secret key