in BiometricAuthentication/app/src/main/java/com/example/android/biometricauth/MainActivity.kt [239:266]
override fun createKey(keyName: String, invalidatedByBiometricEnrollment: Boolean) {
// The enrolling flow for fingerprint. This is where you ask the user to set up fingerprint
// for your flow. Use of keys is necessary if you need to know if the set of enrolled
// fingerprints has changed.
try {
keyStore.load(null)
val keyProperties = KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT
val builder = KeyGenParameterSpec.Builder(keyName, keyProperties)
.setBlockModes(BLOCK_MODE_CBC)
.setUserAuthenticationRequired(true)
.setEncryptionPaddings(ENCRYPTION_PADDING_PKCS7)
.setInvalidatedByBiometricEnrollment(invalidatedByBiometricEnrollment)
keyGenerator.run {
init(builder.build())
generateKey()
}
} catch (e: Exception) {
when (e) {
is NoSuchAlgorithmException,
is InvalidAlgorithmParameterException,
is CertificateException,
is IOException -> throw RuntimeException(e)
else -> throw e
}
}
}