Last updated: April 29, 2026
Android Keystore generates and stores cryptographic keys in hardware (TEE / StrongBox on supported devices). Apps that store secrets correctly use it; many don’t.
The hierarchy
- SharedPreferences — plaintext file in app sandbox. NOT secure.
- EncryptedSharedPreferences — wraps with key from Keystore. Standard.
- Keystore-bound key — never leaves hardware. Highest security.
- Biometric-bound key — only usable after biometric auth.
Common mistakes
- Storing tokens in SharedPreferences
- Using
setUserAuthenticationRequired(false)on sensitive keys - Storing crypto keys in
res/raw/(extractable from APK) - Not validating biometric auth result before key use
Right pattern
val masterKey = MasterKey.Builder(context)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
.setUserAuthenticationRequired(true, AUTH_TIMEOUT)
.build()
val prefs = EncryptedSharedPreferences.create(context, "secrets", masterKey, AES256_SIV, AES256_GCM)
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.