Library for using BiometricPrompt with CryptoObject on Android.
build.gradle
buildscript {
repositories {
maven { url 'https://jitpack.io' }
}
}
settings.gradle
dependencyResolutionManagement {
repositories {
maven { url 'https://jitpack.io' }
}
}
app/build.gradle
implementation 'com.github.prongbang:android-secure-biometric:0.0.6'
- Create class
PinBiometricToken
class PinBiometricToken @Inject constructor() : BiometricToken {
override fun cipherText(): String = token
// Mock storage
companion object {
var token = ""
}
}
- New Instance
val pinBiometricToken = PinBiometricToken()
val secureBiometricManager = SecureBiometricPromptManager.newInstance(this, pinBiometricToken)
val biometricCryptography = BiometricCryptography.newInstance()
- Encrypt
// Mock biometric token from server
val biometricToken = "MOCK_BIOMETRIC_TOKEN_FROM_SERVER"
// Encrypt
val cipherBiometricToken = biometricCryptography.encrypt(biometricToken)
// Save cipher biometric token to local storage
PinBiometricToken.token = cipherBiometricToken
print("Cipher Text: $cipherBiometricToken")
- Decrypt with Biometric
// Authenticate with Biometric
val promptInfo = Biometric.PromptInfo(
title = "BIOMETRIC",
subtitle = "Please scan biometric to Login Application",
description = "description here",
negativeButton = "CANCEL"
)
secureBiometricManager.authenticate(
promptInfo,
object : SecureBiometricPromptManager.Result {
override fun callback(biometric: Biometric) {
when (biometric.status) {
Biometric.Status.SUCCEEDED -> {
// TODO Send biometric.decrypted to Server
// val result = loginWithBiometricToken(biometric.decrypted)
}
Biometric.Status.ERROR -> {}
Biometric.Status.CANCEL -> {}
}
}
})