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) throws

    Parameters

    der

    The DER encoding of the key

  • Creates a private key from its PEM encoding

    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

Stored Properties

  • The domain the key belongs to

    Declaration

    Swift

    public let domain: Domain
  • s

    The private value - a integer number

    Declaration

    Swift

    public let s: BInt

Computed Properties

  • The ASN1 encoding of self

    Declaration

    Swift

    public var asn1: ASN1 { get }
  • pem

    The PEM base 64 encoding of self

    Declaration

    Swift

    public var pem: String { get }
  • A textual representation of the ASN1 encoding of self

    Declaration

    Swift

    public var description: String { get }

Instance Methods

  • 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