If you’re an Android developer, you might have seen this:
EncryptedSharedPreferences
is now deprecated. 😲
Don’t worry — let’s break it down simply, like I’d explain in class.
What is EncryptedSharedPreferences?
Think of EncryptedSharedPreferences as a lockable notebook where your app stores key-value data (like tokens, user settings, passwords). It was designed to encrypt data automatically using AES (symmetric encryption) and keys from the Android Keystore.
Why is it Deprecated?
Google deprecated it because:
- It had performance limitations (slow for frequent reads/writes).
- It didn’t scale well for modern security needs.
- Google now recommends Jetpack Security v1.1.0+ and EncryptedFile, which give better flexibility and security.
The Recommended Alternatives
Instead of EncryptedSharedPreferences, use:
- EncryptedFile (androidx.security.crypto.EncryptedFile)
- Best for saving files securely (JSON, configs, user data).
- Uses AES-GCM encryption for modern security.
- Jetpack Security Crypto APIs
- Use MasterKey + Cipher to handle encryption directly.
- More control, less boilerplate, and future-proof.
Example:
val masterKey = MasterKey.Builder(context)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
.build()
val encryptedFile = EncryptedFile.Builder(
context,
File(context.filesDir, "secure_data.txt"),
masterKey,
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
).build()
encryptedFile.openFileOutput().use { output ->
output.write("Hello Secure World!".toByteArray())
}
Final Takeaway
- Don’t use EncryptedSharedPreferences anymore — it’s deprecated.
- Switch to EncryptedFile or the Crypto APIs in Jetpack Security.
- Think of it like moving from an old lockbox 🔒 to a modern biometric safe 🔐 — faster, safer, and future-ready.
Official Link To Check : https://developer.android.com/reference/kotlin/androidx/security/crypto/EncryptedSharedPreferences
Interview Questions
Q1: Why was EncryptedSharedPreferences deprecated, and what should you use instead?
👉 Answer: It was deprecated due to performance limitations and lack of scalability for modern apps. Instead, Google recommends using EncryptedFile or Jetpack Security’s Crypto APIs for secure data storage.
Q2: When would you choose EncryptedFile over EncryptedSharedPreferences?
👉 Answer: Use EncryptedFile when you need to securely store larger or structured data (like JSON, files, or user profiles). SharedPreferences was meant for small key-value pairs, but EncryptedFile provides stronger security and flexibility for modern use cases.

