I am implemented biometric authentication with BiometricPrompt (androidx). It works well but I can use key only one time. If I trying to use it second time immedatelly after first time - I get an exception UserNotAuthenticatedException. For key creation I am using this code:
KeyGenParameterSpec.Builder(alias, KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
.setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA512)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_OAEP)
.setUserAuthenticationRequired(true)
.build()
I also trying to add .setUserAuthenticationValidityDurationSeconds(10)
to resolve my problem. But it work only after unlock device using power button. And doesn't work BiometricPrompt request. It looks like a bug. Is the solution exists?