Closed osipxd closed 3 years ago
Nice idea. I'll think about it try to implement it as a separate module.
@osipxd, I thought about it a lot and decided that any biometric operations are not the responsibility of this library. If you want "one shot" biometric implementation, I highly recommended paying your attention to the androidx.biometric:biometric-ktx
package. Using it, you'll be able to do things like that:
val cryptoObject = BiometricPrompt.CryptoObject(cipher)
val payload = "A message to encrypt".toByteArray(Charset.defaultCharset())
// Construct AuthPrompt with localized Strings to be displayed to UI.
val authPrompt = Class3BiometricAuthPrompt.Builder(title, negativeButtonText).apply {
setSubtitle(subtitle)
setDescription(description)
setConfirmationRequired(true)
}.build()
try {
val authResult = authPrompt.authenticate(AuthPromptHost(this), cryptoObject)
// Encrypt a payload using the result of crypto-based auth.
val encryptedPayload = authResult.cryptoObject?.cipher?.doFinal(payload)
// Use the encrypted payload somewhere interesting.
sendEncryptedPayload(encryptedPayload)
} catch (e: AuthPromptErrorException) {
// Handle irrecoverable error during authentication.
// Possible values for AuthPromptErrorException.errorCode are listed in the @IntDef,
// androidx.biometric.BiometricPrompt.AuthenticationError.
} catch (e: AuthPromptFailureException) {
// Handle auth failure due biometric credentials being rejected.
}
It would be great to be able to enable biometric authentication "with one line of code". I have not thought about the API yet.