swiftapplications

Apple security for developers: Keychain, Secure Enclave and shipping safely

The Mac gives you a hardware-backed keychain, a Secure Enclave, Touch ID and a sandbox. These guides show how to use them for the thing developers most often get wrong: keeping secrets, like API keys, out of reach.

8 guides, each answered first, with code you can copy.

Apple securityHow to store API keys securely on macOSKeep API keys out of .env files on your Mac: store them in the macOS Keychain, read them only when needed, and keep them away from AI agents.3 min readRead Apple securityKeychain Services in Swift: save, read, update and delete a secretWorking Swift code for the macOS and iOS Keychain: save, read, update and delete a generic password with SecItem, plus the accessibility setting to choose.3 min readRead Apple securityThe Secure Enclave on the Mac with CryptoKit: what it protects and what it can’tCreate 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.3 min readRead Apple securityAsk for Touch ID before releasing a secret (LocalAuthentication and Keychain)Two ways to require Touch ID on a Mac: LocalAuthentication for a prompt, and Keychain access control so the system itself refuses without a fingerprint.3 min readRead Apple securityApp Sandbox on macOS: the entitlements an app actually needsWhat the macOS App Sandbox blocks, the entitlements for network, files and app groups, how to inspect an app’s entitlements, and the 104-byte socket path trap.3 min readRead Apple securityNotarize a Mac app with notarytool: sign, submit, staple, verifyStep-by-step notarization for a Developer ID Mac app and its DMG: hardened runtime, notarytool credentials, submit and wait, staple, and verify with spctl.3 min readRead Apple securityWhy .env files are a risk on a developer Mac (and what to use instead)How .env files leak keys on a Mac: other apps, AI coding agents, backups and Git. Deny-list them for agents, and move keys to the Keychain or a vault.3 min readRead Apple securityUse the macOS security command to keep secrets out of scriptsStore, update, read and delete Keychain secrets from the terminal with the macOS security command, and pass a key to one command instead of your whole shell.3 min readRead

The safe way to do this

MoltenRock

The encrypted vault for your API keys and AI agents

Your keys sealed by your Mac’s Secure Enclave, handed only to the local agents you approve, never written to a .env file. Free for Mac.

Get MoltenRock, free

More field guides