AndroidKeystoreSecureArea

An implementation of SecureArea using Android Keystore.

Keys created using this implementation are hardware-backed, that is the private key material is designed to never leave Secure Hardware. In this context Secure Hardware can mean either the TEE (Trusted Execution Environment) or an SE (Secure Element), specifically anything meeting the definition of an *Isolated Execution Environment as per section 9.11 of the Android CDD.

Any key created will be attested to by the Secure Hardware, using Android Keystore Key Attestation. This gives remote parties (such as real-world identity document issuers) a high level of assurance that the private part of the key exists only in Secure Hardware and also gives a strong signal about the general state of the device (including whether verified boot is enabled, latest patch level, etc.) and which particular Android application (identified by Application Id) created the key.

Curve EcCurve.P256 for signing using algorithm Algorithm.ES256 is guaranteed to be implemented in Secure Hardware on any Android device shipping with Android 8.1 or later. As of 2024 this includes nearly all Android devices.

If the device has a StrongBox Android Keystore, keys can be stored there using CreateKeySettings.Builder.setUseStrongBox.

Other optional features may be available depending on the version of the underlying software (called Keymint) running in the Secure Area. The Capabilities helper class can be used to determine what the device supports.

This implementation works only on Android and requires API level 24 or later.

Use AndroidKeystoreSecureArea.create to create an instance of this class.

Types

Link copied to clipboard

Helper class to determine capabilities of the device.

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val displayName: String

The name of the Secure Area, suitable for displaying to the end user.

Link copied to clipboard
open override val identifier: String

A stable identifier for the Secure Area.

Link copied to clipboard
open override val supportedAlgorithms: List<Algorithm>

The list of algorithms the Secure Area supports.

Functions

Link copied to clipboard
open suspend fun batchCreateKey(numKeys: Int, createKeySettings: CreateKeySettings): BatchCreateKeyResult

Creates a batch of new keys.

Link copied to clipboard
open suspend override fun createKey(alias: String?, createKeySettings: CreateKeySettings): AndroidKeystoreKeyInfo

Creates a new key.

Link copied to clipboard
suspend fun createKeyForExistingAlias(existingAlias: String)

Creates a key for an existing Android KeyStore key.

Link copied to clipboard
open suspend override fun deleteKey(alias: String)

Deletes a previously created key.

Link copied to clipboard
open suspend override fun getKeyInfo(alias: String): AndroidKeystoreKeyInfo

Gets information about a key.

Link copied to clipboard
open suspend override fun getKeyInvalidated(alias: String): Boolean

Checks whether the key has been invalidated.

Link copied to clipboard
open suspend override fun keyAgreement(alias: String, otherKey: EcPublicKey, keyUnlockData: KeyUnlockData?): ByteArray

Performs Key Agreement.

Link copied to clipboard
open suspend override fun sign(alias: String, dataToSign: ByteArray, keyUnlockData: KeyUnlockData?): EcSignature

Signs data with a key.