Security

    Is SharedPreferences secure? Encrypting Android prefs

    A 2026 view contrasting a token stored in plain Android SharedPreferences with secrets protected by a Keystore-backed key, noting EncryptedSharedPreferences is deprecated

    SharedPreferences is the easy way to persist small values on Android, and it is not secure: it writes plain, unencrypted data, so a token or secret stored there is readable on a compromised or backed-up device. For years the answer was Jetpack Security's EncryptedSharedPreferences, but that library is now deprecated with no further releases, so it is no longer the recommendation for new apps. The underlying principle has not changed: keep secrets out of plain storage and protect them with the Keystore. Here is whether SharedPreferences is secure, what the deprecation means, and how to store sensitive data on Android now.

    Short answer

    SharedPreferences stores key-value data in plain, unencrypted form, so it is not a place for secrets, which can be read off a compromised or backed-up device. Jetpack Security's EncryptedSharedPreferences used to provide Keystore-backed encryption for preferences, but per Android's release notes it is deprecated as of version 1.1.0 with no further releases, and Google advises against using it in new apps. The durable approach is unchanged: keep cryptographic keys and small secrets in the Android Keystore, store any sensitive values with Keystore-backed encryption or a maintained secure-storage solution, and reserve plain SharedPreferences for non-sensitive settings. The principle is that secrets do not belong in plain preferences.

    What you should know

    • SharedPreferences is plain: it stores values unencrypted.
    • Secrets there are exposed: readable on a compromised or backed-up device.
    • EncryptedSharedPreferences is deprecated: no further releases; not for new apps.
    • Use the Keystore for keys and secrets: hardware-backed and not extractable.
    • Plain prefs are fine for non-sensitive settings: just not for secrets.

    Is SharedPreferences secure?

    No, not for sensitive data. SharedPreferences persists its data as a plain XML file in your app's data directory, with no encryption, so any value stored there, including a token, password, or API key, is readable by anyone who can access the app's files, which includes someone inspecting a rooted device or a device backup. It is a convenient store for small, non-sensitive values like a theme setting or a flag, but treating it as secure storage is the mistake. This is the Android equivalent of the iOS UserDefaults situation: a fine place for preferences, a leak for secrets. So the question is not how to make SharedPreferences itself secure, but where sensitive data should go instead, since plain preferences will always expose it.

    What does the EncryptedSharedPreferences deprecation mean?

    That the convenient drop-in for encrypted preferences is no longer the path forward. The table summarizes the situation.

    AspectStatus
    Plain SharedPreferencesUnencrypted; not for secrets
    EncryptedSharedPreferences (Jetpack Security)Deprecated at 1.1.0; no further releases
    Google's guidanceAdvises against it in new apps
    The KeystoreThe durable place for keys and secret protection

    EncryptedSharedPreferences offered Keystore-backed encryption of preference data, and it still functions for apps that use it, but its deprecation means it will not receive further updates and is not recommended for new development. That does not change the goal, encrypting sensitive data at rest, only the specific library you reach for. The Android Keystore, which holds keys that cannot be extracted, remains the foundation, and you protect sensitive values with a Keystore-backed key rather than relying on a deprecated convenience wrapper.

    How do you store sensitive data on Android now?

    Keep keys and small secrets in the Keystore, and encrypt sensitive values with a Keystore-backed key. For cryptographic keys and small secrets like tokens, use the Android Keystore directly, generating and using keys that stay in secure, often hardware-backed, storage and cannot be exported. For larger sensitive values you need to persist, encrypt them with a key held in the Keystore rather than writing them in plain SharedPreferences, using a current, maintained approach for the encryption rather than the deprecated library. Reserve plain SharedPreferences for genuinely non-sensitive settings, where its convenience is fine. And the strongest option for some data is not to store it on the device at all, keeping it on your backend. The principle is the same one that predates the deprecation: secrets are protected by the Keystore, not by a plain preferences file.

    What to watch out for

    The first trap is storing a token, password, or key in plain SharedPreferences, which exposes it; keep secrets in the Keystore. The second is reaching for EncryptedSharedPreferences in a new app, since it is deprecated and unmaintained; use a current Keystore-backed approach. The third is treating any local storage as a vault for a long-lived secret that would be safer on your backend. A pre-submission scan such as PTKD.com (https://ptkd.com) reads the compiled APK or AAB against OWASP MASVS and flags sensitive data stored insecurely, such as secrets in plain SharedPreferences, so you can move them to secure storage before you ship. The storage choices you make in the app.

    What to take away

    • SharedPreferences stores data in plain, unencrypted form, so it is not a place for tokens, passwords, or keys.
    • EncryptedSharedPreferences is deprecated as of 1.1.0 with no further releases, so it is not the recommendation for new apps.
    • Keep cryptographic keys and small secrets in the Android Keystore, encrypt sensitive values with a Keystore-backed key, and reserve plain SharedPreferences for non-sensitive settings.
    • Use a pre-submission scan such as PTKD.com to catch secrets stored in plain SharedPreferences before you ship.
    • #android
    • #sharedpreferences
    • #encryptedsharedpreferences
    • #keystore
    • #secure-storage
    • #owasp-masvs
    • #app-security

    Frequently asked questions

    Is Android SharedPreferences secure?
    No, not for sensitive data. SharedPreferences persists data as a plain XML file in your app's data directory with no encryption, so a token, password, or API key stored there is readable by anyone who can access the app's files, including on a rooted device or a backup. It is fine for small non-sensitive values like settings and flags, but it is the Android equivalent of iOS UserDefaults: a leak for secrets, which belong in the Keystore instead.
    Is EncryptedSharedPreferences still recommended?
    No. Jetpack Security's EncryptedSharedPreferences provided Keystore-backed encryption of preferences, but it is deprecated as of version 1.1.0 with no further releases, and Google advises against using it in new apps. It still functions for apps that use it, but it will not be maintained. The deprecation does not change the goal of encrypting sensitive data at rest, only the library you reach for; the Android Keystore remains the foundation for protecting secrets.
    Where should I store secrets on Android now?
    Keep cryptographic keys and small secrets in the Android Keystore, which holds keys in secure, often hardware-backed storage that cannot be extracted. For larger sensitive values you must persist, encrypt them with a key held in the Keystore using a current, maintained approach rather than plain SharedPreferences or the deprecated EncryptedSharedPreferences. And for some data, the safest choice is not to store it on the device at all, keeping it on your backend instead.
    Can I still use plain SharedPreferences?
    Yes, for non-sensitive data. SharedPreferences is a fine, convenient store for settings, preferences, and flags you would not mind anyone reading, since those carry no risk if exposed. The rule is simply that it must never hold secrets like tokens, passwords, or keys, because it stores everything in plain text. So use SharedPreferences for ordinary preferences and the Keystore for anything confidential, and its convenience stops being a liability.
    How do I find secrets stored in plain SharedPreferences?
    Scan the build. A pre-submission scan such as PTKD.com reads the compiled APK or AAB against OWASP MASVS and flags sensitive data stored insecurely, such as a token or key in plain SharedPreferences, so you can confirm secrets go to the Keystore before you ship. If it finds a secret in plain preferences, the fix is to move it to Keystore-backed secure storage, and to reserve SharedPreferences for non-sensitive settings.

    Keep reading

    Scan your app in minutes

    Upload an APK, AAB, or IPA. PTKD returns an OWASP-aligned report with copy-paste fixes.

    Try PTKD free