swiftapplications

Apple security for developers

The Secure Enclave on the Mac with CryptoKit: what it protects and what it can’t

Create Secure Enclave keys on Apple silicon and T2 Macs with CryptoKit, require Touch ID to use them, and see why an API key can’t simply live inside the enclave.

Updated 8 October 2026 3 min read

The short answer

The Secure Enclave is a separate processor in Apple silicon Macs and Intel Macs with a T2 chip. With CryptoKit you can create keys that are generated and used inside it and can never be exported, and you can require Touch ID for each use. It holds keys, not arbitrary data: to protect an API key you encrypt it with an enclave-backed key or a keychain item tied to the enclave.

Check that it’s there

swift
import CryptoKit

guard SecureEnclave.isAvailable else {
    // Intel Macs without a T2 chip, or a virtual machine
    fatalError("No Secure Enclave on this Mac")
}

Create a key that never leaves the enclave

swift
let access = SecAccessControlCreateWithFlags(
    nil,
    kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
    [.privateKeyUsage, .biometryCurrentSet],   // Touch ID for every use
    nil
)!

let key = try SecureEnclave.P256.Signing.PrivateKey(accessControl: access)

// An encrypted handle that only this Mac's enclave can use. Store it (for example in the Keychain).
let handle = key.dataRepresentation

// Later: restore the key from the handle and sign
let restored = try SecureEnclave.P256.Signing.PrivateKey(dataRepresentation: handle)
let signature = try restored.signature(for: Data("hello".utf8))
let ok = restored.publicKey.isValidSignature(signature, for: Data("hello".utf8))

dataRepresentation is not the private key. It is a blob that only this device’s Secure Enclave can unwrap, so copying it to another Mac is useless.

What it can’t do

  • It doesn’t store arbitrary secrets. An API key has to be encrypted with an enclave key, or stored as a keychain item whose access control requires the enclave and Touch ID.
  • It can’t protect a secret after you hand it to another program. Once a process has the plain key, the enclave is out of the picture.
  • Keys are tied to the device. Plan for re-enrolment when someone gets a new Mac.

That second point is the important one for AI agents: the protection has to sit between the agent and the key, deciding each time whether to use it, not just encrypt it at rest.

Touch ID, the right way

Putting .biometryCurrentSet in the access control makes the hardware demand a fingerprint; there is no if-statement in your app for malware to skip. .biometryCurrentSet also invalidates the key if fingerprints are added or removed. The Touch ID guide covers LocalAuthentication too.

The safe way to do this

MoltenRock

The encrypted vault for your API keys and AI agents

MoltenRock seals your keys with your Mac’s Secure Enclave and decides, each time, which agent gets one.

Get MoltenRock, free

Questions developers ask

Which Macs have a Secure Enclave?

All Apple silicon Macs, and Intel Macs with the Apple T2 Security Chip.

Can I store an API key in the Secure Enclave?

Not directly. Encrypt it with an enclave-backed key, or store it in the Keychain with access control that requires the enclave and Touch ID.

What happens to Secure Enclave keys when I restore from a backup?

They don’t come back. The handle restores, but only the original device’s enclave can use it, so create new keys after moving to a new Mac.