Last updated: April 29, 2026
iOS Keychain is hardware-backed. Data Protection classes determine when items are accessible.
Data Protection classes
- kSecAttrAccessibleWhenUnlocked — accessible only when device unlocked. Default for new items.
- kSecAttrAccessibleAfterFirstUnlock — after first unlock until reboot. For background tasks.
- kSecAttrAccessibleAlways — anytime. AVOID; deprecated.
- WhenPasscodeSet variants — only if user has passcode set; deletes if passcode removed.
- WhenUnlockedThisDeviceOnly — not synced via iCloud Keychain.
Common mistakes
- Using
AccessibleAlwaysfor sensitive data - Not setting
ThisDeviceOnlyfor device-specific secrets (sync exposes them via iCloud) - Storing in NSUserDefaults instead of Keychain
Secure Enclave
For asymmetric keys, use Secure Enclave: kSecAttrTokenIDSecureEnclaveTokenID. Private key never leaves Secure Enclave; signing operations happen there.
Module Quiz · 6 questions
Pass with 80%+ to mark this module complete. Unlimited retries. Each question shows an explanation.
Custom team training + practitioner advisory
Beyond the free academy — we run private workshops, vCISO advisory, and red-team exercises tailored to your stack. For Indian SMBs scaling past their first hire.