BiometricGate
Wraps BiometricPrompt + BiometricPrompt.CryptoObject as a suspend function.
Provides per-use authentication gating for cryptographic operations. Each call shows the system biometric prompt (fingerprint, face, or PIN fallback) and returns an AuthenticatedCipher that can perform exactly one crypto operation.
Security model (verified against AOSP):
CryptoObject binds authentication to a specific
beginOperation()in KeyMintThe HardwareAuthToken's
challengefield matches the operation handleThis provides TEE-level per-operation enforcement — not just time-based
Works with
AUTH_BIOMETRIC_STRONG | AUTH_DEVICE_CREDENTIALon API 30+ (AndroidX biometric 1.1.0 stable)
Functions
Authenticates the user and returns a cipher ready for decryption.
Authenticates the user and returns a cipher ready for encryption.
Attempts to decrypt ciphertext with the master key WITHOUT showing a BiometricPrompt. Succeeds silently when the Keystore auth-validity window (set via AuthPolicy.VALIDITY_DURATION_SECONDS) is currently open for the key. The caller MUST wipe the returned bytes once it's done with the plaintext.
Attempts to obtain a Cipher initialized for encryption with the master key WITHOUT showing a BiometricPrompt. Returns a fresh, unused Cipher when the auth-validity window is open; null when expired or anything else goes wrong, in which case the caller should fall back to authenticateForEncrypt.