CryptoKey

public class CryptoKey

A class for managing cryptographic keys in the Keychain. This class provides methods for generating, retrieving, and deleting key pairs.

  • The tag that uniquely identifies the key in the Keychain.

    Declaration

    Swift

    public let keyTag: String
  • Initializes a new CryptoKey with the given key tag.

    Declaration

    Swift

    public init(keyTag: String)

    Parameters

    keyTag

    The key tag to use.

  • Generates a new elliptic curve key pair and stores it in the Secure Enclave.

    Throws

    A DeviceBindingError if the key generation fails.

    Declaration

    Swift

    public func generateKeyPair(attestation: Attestation, accessControl: SecAccessControl? = nil, keySizeInBits: Int = 256, pin: String? = nil) throws -> KeyPair

    Parameters

    attestation

    The attestation type. Currently, this parameter is not used.

    accessControl

    The access control flags for the key. If nil, a default will be used.

    keySizeInBits

    The key size in bits (256 for P-256, 521 for P-521). Defaults to 256.

    Return Value

    The generated KeyPair.

  • Gets the public key from the Keychain.

    Throws

    A DeviceBindingError.deviceNotRegistered if the key is not found.

    Declaration

    Swift

    public func getPublicKey() throws -> SecKey

    Return Value

    The public key as a SecKey.

  • Deletes the key pair from the Keychain.

    Throws

    A DeviceBindingError.unknown if the deletion fails for any reason other than the item not being found.

    Declaration

    Swift

    public func deleteKeyPair() throws