Android Keystore and secure hardware, explained

What the Android Keystore, the TEE and StrongBox are, what "hardware-backed key" really protects, and how a photo vault uses them.

Part of: Encryption and securityUpdated November 24, 20269 min read

The Android Keystore is Android's built-in service for cryptographic keys that apps can use but can't read or copy. When a key is created in the Keystore, the key itself stays out of the app's memory, and on most phones it is bound to secure hardware: either the TEE (Trusted Execution Environment), a walled-off part of the main processor, or StrongBox, a separate security chip that some phones have since Android 9. Apps send data in and get results back; the key never comes out. For a photo vault, this is what stops someone from copying the encrypted files to a computer and guessing the PIN there at full speed. Below we explain each piece using Android's own documentation, show where the protection ends, and how HideBerry, the vault we make, uses it.

This page is part of photo encryption and security explained.

What the Android Keystore is

Android's developer documentation describes the Keystore as a container that makes keys "more difficult to extract from the device". The Android Keystore provider has been part of Android since Android 4.3 (API level 18).

It protects keys in two ways, according to Google:

  1. The key never enters the app. When an app encrypts or decrypts with a Keystore key, the data is passed to a system process that does the work. If the app itself is compromised, an attacker might be able to use the app's keys, but can't pull out the key material to use somewhere else.
  2. The key can be bound to secure hardware. When this is turned on for a key, the key is never exposed outside the secure hardware. Google spells out the limit too: if the Android OS is compromised, or an attacker can read the phone's storage, that attacker might be able to use an app's Keystore keys on the device, but can't extract them from it.

Keys can also carry rules set when they are created, which the Keystore enforces outside the app: which operations are allowed, and whether the user must have recently unlocked or authenticated before the key works. Once created, those rules can't be changed.

The TEE: a locked room inside the main processor

The TEE, or Trusted Execution Environment, is a secure, isolated area of the phone's processor that runs its own small operating system for sensitive work such as handling keys. Android's open-source TEE is called Trusty. The Android Open Source Project describes it as running on the same processor as Android but isolated from the rest of the system, and on ARM chips it uses ARM's TrustZone to create that separation. That isolation is meant to protect it from malicious apps and from weaknesses in Android itself.

On most Android phones, hardware-backed Keystore keys live in the TEE.

StrongBox: a separate security chip

StrongBox is the stronger tier. Phones running Android 9 or higher can include it; not all do. Google's developer documentation says StrongBox hardware must have:

  • its own CPU
  • secure storage
  • a true random-number generator
  • extra resistance to package tampering and unauthorized sideloading
  • a secure timer
  • a reboot notification pin or equivalent

Google describes StrongBox as an embedded secure element or integrated secure enclave that gives "stronger isolation and tamper resistance compared to the TEE". The cost is speed: StrongBox is slower, has fewer resources and handles fewer operations at once, and it supports a smaller set of algorithms (AES 128 and 256 are on the list). Apps ask for StrongBox when creating a key and fall back to the TEE when the phone doesn't have it or doesn't support the requested key.

Software, TEE and StrongBox compared

Key kept in app storageKeystore key in the TEEKeystore key in StrongBox
Where the key livesA file the app can readIsolated area of the main processorSeparate chip with its own CPU and storage
Can malware inside the app read the key?YesNo, it can only ask for operationsNo, it can only ask for operations
Can someone who reads the phone's storage copy the key?YesNoNo
Resistance to physical tamperingNoneShares the main processorDesigned to resist tampering and side-channel attacks
SpeedFastFastSlower
Available onEvery phonePhones whose secure hardware supports the key typeSome phones running Android 9 or newer

What "hardware-backed" protects, and what it doesn't

This is the part most explanations skip. A hardware-bound key can't be taken. It can still be used on the phone, by whoever can get the phone to use it.

It protects against:

  • Copying the vault's files to a computer and trying PINs there, where guesses could run far faster than on the phone.
  • Someone who can read the phone's storage, for example from a backup image, walking away with the key.
  • Malware in another app reading the key from memory.

It does not protect against:

  • Someone who has the phone unlocked and tries PINs through the app. The key is still usable on that phone; guessing protection and lockouts covers what slows this down.
  • An attacker who has compromised the Android OS on the phone itself. Google's documentation says such an attacker might use the keys on the device, even though they can't extract them.
  • Anything already decrypted and on screen.

So the Keystore changes where an attack has to happen: on your phone, at the phone's speed, under the app's rules. It does not make the phone itself out of reach. The full list of limits is on what a photo vault can't stop.

How HideBerry uses the Keystore

In HideBerry, the vault's master key is random and never made from your PIN. To unlock it:

  1. Your PIN or pattern goes through Argon2id (64 MiB of memory, 3 passes), a slow function that turns a short code into a key.
  2. That result is wrapped again by a key held in the Android Keystore: in StrongBox when the phone has it, otherwise in the TEE. That hardware key can't be copied off the phone.
  3. With a phone screen lock set, the hardware key only works while the phone is unlocked.

What this means in practice:

  • Files copied off the phone can't be opened with the PIN alone. The hardware half stays on the chip.
  • A locked phone keeps the vault shut harder. If you use a screen lock (we recommend it), the vault's device key can't be used while the phone is locked, even by someone who knows your vault PIN.
  • Removing the screen lock later can cost you that key. If Android drops the key when the screen lock is removed, your 12 recovery words get you back in on the same phone, with everything there.
  • A new phone uses a different path. Because the hardware key can't leave the old phone, restoring uses your backup file and 12 recovery words instead. Nothing from the old phone is needed. See move a photo vault to a new phone.
  • Fingerprint unlock starts off after a restore. You switch it on again on the new phone.

Your lock screen uses the same hardware

Your phone's own screen lock leans on the TEE too. Android's Gatekeeper checks your screen lock PIN, pattern or password inside the TEE, and it must throttle repeated wrong attempts from inside the secure environment, writing a failure counter before each check so it can't be skipped by cutting storage. This is one reason we recommend a strong screen lock alongside any vault: its guessing limits are enforced in hardware, while an app's own waits run in the app.

How Keystore hardware grew, by Android version

From the Android Open Source Project's version history of the Keystore hardware layer:

Android versionWhat changed
Android 6.0Keymaster 1.0: symmetric keys and access control
Android 7.0Keymaster 2: key attestation and version binding
Android 8.0Keymaster 3: ID attestation
Android 9Keymaster 4, and support for embedded secure elements (StrongBox)
Android 10Keymaster 4.1, optional device-unique attestation in StrongBox
Android 12KeyMint replaces Keymaster
Android 13KeyMint version 2

HideBerry works on Android 9 and newer, the release where StrongBox support arrived.

Myths about the Keystore

  • "The Keystore stores my photos." It stores keys, not files. Your photos are encrypted files in the app's storage; the Keystore holds a key that helps unlock them.
  • "Hardware-backed means nobody can ever get in." It means the key can't be copied out. Use on the device is still possible for whoever controls it.
  • "Every phone has StrongBox." Phones running Android 9 or newer can include it. Phones without it use the TEE.
  • "A fingerprint is stored in the app." With Android's biometric system, the phone checks the fingerprint; HideBerry never receives it.

People Also Ask

How do I know if my phone has StrongBox? Apps can check a system feature called FEATURE_STRONGBOX_KEYSTORE. Android doesn't show it in a standard settings screen we can point to across phone makers. HideBerry chooses StrongBox automatically when the phone has it.

Is the TEE safe enough without StrongBox? For keeping a key from being copied off the phone, yes: Google's documentation treats TEE-bound keys as non-extractable. StrongBox adds resistance to physical tampering and side-channel attacks, which matters most against well-equipped attackers with the phone in hand.

What happens to my vault if I uninstall HideBerry? Deleting the app deletes the vault on that phone. The hardware key can't be moved anyway, so the way to keep your photos across an uninstall or a new phone is a recent backup file saved off the phone, plus your 12 recovery words on paper.

Can a repair shop read Keystore keys? Not by copying them; they are bound to the hardware. A shop with your unlocked phone is a different matter, which is why we cover that on what a photo vault can't stop.

FAQs

What is the Android Keystore in simple terms?

It is a safe for keys built into Android. Apps can ask it to create a key and then use that key to encrypt or decrypt, but they can't read the key itself. On most phones the key is also bound to secure hardware, so it can't be copied off the device.

What is the difference between the TEE and StrongBox?

The TEE is an isolated area inside the phone's main processor. StrongBox is a separate security chip with its own CPU, secure storage and random-number generator. Google describes StrongBox as having stronger isolation and tamper resistance, but it is slower and not every phone has it.

Can hardware-backed keys be extracted if my phone is rooted?

Google's documentation says that even if the Android OS is compromised, an attacker can't extract hardware-bound keys from the device, though they might be able to use them on it. So root doesn't let someone copy the key away, but it can let them use the phone to try things.

Why can't I just move my vault files to a new phone?

Because part of the key lives in the old phone's secure hardware and can't move. In HideBerry you make a backup file, which opens with your 12 recovery words on any phone. That is the intended way to move.

Does HideBerry require StrongBox?

No. HideBerry uses StrongBox when the phone has it, and the TEE otherwise. It works on Android 9 and newer.

See how this fits HideBerry's security

The Keystore is one layer in HideBerry's design, next to per-item AES-256-GCM encryption, Argon2id and wrong-attempt waits. HideBerry is coming soon to Google Play. Read the full design and its stated limits on HideBerry security, or how the layers fit together on how photo encryption works.

Sources

Keep private photos private

HideBerry encrypts photos, videos, notes and files on your Android phone. No account, no cloud, no ads. Free for up to 50 items, with every feature.

Coming soon toGoogle PlaySee how it works