String

struct String

Extensions for encrypting or signing a String by converting it to UTF8 Data, then using the appropriate algorithm determined by the key’s curve with the provided ECPrivateKey or ECPublicKey.

  • UTF8 encode the String to Data and encrypt it using the ECPublicKey. This either uses the SecKeyAlgorithm: eciesEncryptionStandardVariableIVX963SHA256AESGCM, or the equivalent OpenSSL implementation.

    Throws

    An ECError is the plaintext fails to be encrypted.

    Declaration

    Swift

    public func encrypt(with key: ECPublicKey) throws -> Data

    Parameters

    ecPrivateKey

    The elliptic curve private key.

    Return Value

    The encrypted Data.

  • UTF8 encode the String to Data and sign it using the ECPrivateKey. The Data is signed using ECDSA with either SHA256, SHA384 or SHA512, depending on the key’s curve.

    Throws

    An ECError if a valid signature is unable to be created.

    Declaration

    Swift

    public func sign(with key: ECPrivateKey) throws -> ECSignature

    Return Value

    An ECSignature on failure.