Data Storage Security Quiz

SECURITY › Security

An attacker fully compromises your app's process at runtime on a device with a hardware-backed Keystore. What can they do with a key generated in the Keystore?

Answer: Use the key for crypto while the process runs, but not extract it

Keystore keys are non-exportable: operations are delegated to a system process or secure hardware, so a compromised app can invoke the key but never read or copy the key material.

How does EncryptedSharedPreferences encrypt the preference KEYS (not the values)?

Answer: AES256-SIV, a deterministic scheme for lookupable encrypted keys

Keys use AES256-SIV, which is deterministic so the same plaintext key always maps to the same ciphertext, enabling lookups; values use the randomized authenticated AES256-GCM.

Which of these is the WORST practice?

Answer: Saving an OAuth refresh token as plain text in SharedPreferences

A refresh token in plain SharedPreferences sits in unencrypted XML readable on rooted devices and via backups; long-lived secrets must be encrypted with a Keystore-backed key.

You want a Keystore key that can only be used immediately after the user passes a biometric check, with no time window. Which configuration is correct?

Answer: setUserAuthenticationRequired(true), 0-second timeout, one CryptoObject per operation

A timeout of 0 forces per-operation authentication; you wrap the Cipher in a CryptoObject and pass it to BiometricPrompt so the key is authorized for exactly that one operation.

What is the key practical difference between a StrongBox-backed key and a TEE-backed key?

Answer: StrongBox uses a discrete secure element, so it is tougher but slower to operate

StrongBox is a discrete secure element with its own CPU/storage/RNG, offering stronger physical tamper resistance than the on-SoC TEE, at the cost of speed, fewer algorithms, and limited concurrent operations.

Under scoped storage (Android 11+), how should an app let the user import an arbitrary PDF from anywhere on the device?

Answer: Use the Storage Access Framework (ACTION_OPEN_DOCUMENT) for a granted URI

Scoped storage removes broad filesystem access; the Storage Access Framework lets the user pick a file and grants the app a scoped content URI, which is the correct and policy-compliant path.

What is the current (2026) status of the EncryptedSharedPreferences / Jetpack Security Crypto library?

Answer: Deprecated in 2024 and unmaintained; use the Keystore or encrypt data yourself

androidx.security:security-crypto was deprecated in 2024; it still runs but receives no fixes, so new code should use the Keystore (or Tink) directly or encrypt before writing to prefs/DataStore/files.

Your backend needs cryptographic proof that a specific key was actually generated inside the device's secure hardware and is non-exportable. What does the Keystore provide for this?

Answer: Key attestation: a signed X.509 chain rooted in Google attestation

Key attestation produces a certificate chain signed by a Google-rooted attestation key that lets a remote server verify the key's security level, origin, and that it is hardware-backed and non-exportable; a client-sent boolean is trivially spoofed by a compromised app.

By default, what happens to a biometric-bound Keystore key when the user enrolls a NEW fingerprint or face on the device?

Answer: The key is permanently invalidated and can no longer be used

invalidatedByBiometricEnrollment defaults to true, so enrolling a new biometric permanently invalidates the key, defending against an attacker who adds their own biometric; you can opt out with setInvalidatedByBiometricEnrollment(false).

You want a Keystore key whose cryptographic operations only succeed while the screen is unlocked, so background code cannot decrypt data on a locked device. Which builder option enforces this?

Answer: setUnlockedDeviceRequired(true)

setUnlockedDeviceRequired(true) restricts the key to use only while the device is unlocked; the other options govern IV randomization, the post-auth validity window, and secure-element backing respectively.

With Jetpack Security Crypto deprecated, which Google-maintained library is a recommended higher-level option for developers who do not want to call the raw Keystore APIs directly?

Answer: Tink with a keyset wrapped by an Android Keystore master key

Google recommends Tink, whose Android integration stores a keyset encrypted by a Keystore-wrapped master key, giving misuse-resistant AEAD without hand-rolling crypto; the other options either lack hardware backing or rely on a hardcoded key.

A teammate migrates from SharedPreferences to Jetpack DataStore (Preferences) and claims the data is now encrypted at rest. Are they correct?

Answer: No, DataStore is plaintext on disk by default; encrypt secrets first.

DataStore fixes the threading and consistency problems of SharedPreferences but adds no encryption; the file is plaintext on disk (a binary format is not a security boundary), so secrets must be encrypted with a Keystore-backed key first.

When you encrypt multiple records yourself with an AES-GCM key, why must you never reuse the same IV/nonce with the same key?

Answer: Nonce reuse in GCM can reveal plaintext XOR and the auth subkey

GCM is broken by nonce reuse under the same key, potentially exposing the GHASH authentication subkey and the XOR of messages; for Keystore keys, randomizedEncryptionRequired defaults to true so the system supplies a fresh random IV per operation.

An app stores Keystore-encrypted secrets in SharedPreferences with auto-backup enabled, and the encrypted XML is backed up to the cloud and restored onto a NEW device. Can a thief who obtains that backup decrypt the secrets?

Answer: No; Keystore keys never leave the device, so restored ciphertext is undecryptable

Keystore keys are non-exportable and are never included in backups, so ciphertext restored to a different device is undecryptable; you should still exclude sensitive files from auto-backup as defense in depth.

Back to Data Storage Security