AndroidTokenEncryptionHandler

class AndroidTokenEncryptionHandler(keyAlias: String = DEFAULT_KEY_ALIAS, requireBiometric: Boolean = false, userAuthenticationTimeout: Int = 5, promptInfo: BiometricPrompt.PromptInfo? = null, keyStore: KeyStore = AndroidKeystoreUtil.keyStore, keyPairGenerator: KeyPairGenerator = AndroidKeystoreUtil.getRsaKeyPairGenerator()) : TokenEncryptionHandler

Android TokenEncryptionHandler backed by the Android Keystore, with optional biometric gating.

A single instance encrypts with one fixed policy chosen at construction — either a plain Keystore-resident RSA/AES envelope (requireBiometric = false), or the same envelope protected by a biometric-gated key (requireBiometric = true). This mirrors the JVM JceTokenEncryptionHandler's "one strategy per instance" model. For per-credential mixed security tiers (some biometric, some not), construct multiple RoomTokenStorage instances with different keyAlias values.

promptInfo must be non-null before a decrypt call is attempted when requireBiometric is true, or that call fails with IllegalArgumentException. If different operations need different prompt text, construct separate RoomTokenStorage instances (see keyAlias above) rather than mutating this instance — neither TokenStorage.getToken nor TokenEncryptionHandler.decrypt take a per-call prompt, so a single instance can only ever show one prompt anyway.

Parameters

keyAlias

the Android Keystore alias used for this handler's RSA key pair.

requireBiometric

when true, a biometric (or device credential, depending on Keystore capability) challenge is required to decrypt.

userAuthenticationTimeout

seconds after a successful biometric challenge during which decryption may proceed without re-prompting; 0 means "auth-per-use" (every decrypt shows the prompt). Ignored when requireBiometric is false.

promptInfo

the BiometricPrompt.PromptInfo to display for biometric challenges. Required (non-null) when requireBiometric is true.

keyStore

the KeyStore used to store/retrieve the RSA key pair.

keyPairGenerator

the generator used to create the RSA key pair on first use.

Constructors

Link copied to clipboard
constructor(keyAlias: String = DEFAULT_KEY_ALIAS, requireBiometric: Boolean = false, userAuthenticationTimeout: Int = 5, promptInfo: BiometricPrompt.PromptInfo? = null, keyStore: KeyStore = AndroidKeystoreUtil.keyStore, keyPairGenerator: KeyPairGenerator = AndroidKeystoreUtil.getRsaKeyPairGenerator())

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open suspend override fun decrypt(ciphertext: ByteArray, encryptionExtras: Map<String, String>): ByteArray

Decrypts the given ciphertext bytes.

Link copied to clipboard
open suspend override fun encrypt(plaintext: ByteArray): EncryptionResult

Encrypts the given plaintext bytes.