Module 10 · iOS Keychain & Data Protection

Manish Garg
Manish Garg Associate of (ISC)² · RingSafe
Apr 27, 2026
1 min read
Read as

Last updated: April 29, 2026

100% Free

No signup. No paywall. No catch. One of our 10 most-requested practitioner modules — published in full so anyone can learn for free. We earn through consulting, not by gating knowledge.

See all 10 free modules →

iOS Keychain is hardware-backed. Data Protection classes determine when items are accessible.

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 AccessibleAlways for sensitive data
  • Not setting ThisDeviceOnly for 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.

🧠
Check your understanding

Module Quiz · 6 questions

Pass with 80%+ to mark this module complete. Unlimited retries. Each question shows an explanation.

Want this for your team?

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.

Book team training call Replies in 4 working hrs · India-only · Senior consultants