在我的应用程序中注册指纹验证后尝试生成 key 对时,三星 S20、S20+ 和 S20 Ultra 设备出现问题。我们只在配备 Exynos 芯片组(国际型号)而非 Snapdragon 的全新三星 S20 系列上看到此问题,但在任何其他设备上都没有。我用美国规范的三星 S20+ 对其进行了测试,但无法重现该问题。
这是个异常(exception)。
Caused by: java.security.ProviderException: Failed to generate key pair
at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.generateKeystoreKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:556)
at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.generateKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:499)
at java.security.KeyPairGenerator$Delegate.generateKeyPair(KeyPairGenerator.java:727)
at com.x.biometricskit.provider.BioKeyGeneratorImpl.generateKeyPair(BioKeyGenerator.kt:70)
... 34 more
Caused by: android.security.KeyStoreException: Unsupported digest
at android.security.KeyStore.getKeyStoreException(KeyStore.java:1539)
... 38 more
这是 BioKeyGeneratorImpl.generateKeyPair 的代码 fragment 。
fun generateKeyPair(keyStoreAlias: String): KeyPair? {
val specBuilder: KeyGenParameterSpec.Builder =
KeyGenParameterSpec.Builder(keyStoreAlias, KeyProperties.PURPOSE_SIGN)
.setAlgorithmParameterSpec(ECGenParameterSpec(EC_KEY_SPEC))
.setDigests(
KeyProperties.DIGEST_SHA256,
KeyProperties.DIGEST_SHA384,
KeyProperties.DIGEST_SHA512
)
.setUserAuthenticationRequired(true)
.setIsStrongBoxBacked(true)
.setInvalidatedByBiometricEnrollment(true)
val keyPairGenSpec = specBuilder.build()
val keyPairGenerator =
KeyPairGenerator.getInstance(
KeyProperties.KEY_ALGORITHM_EC,
"AndroidKeyStore"
)
keyPairGenerator.initialize(keyPairGenSpec)
return keyPairGenerator.generateKeyPair()
}
最佳答案
我改成了
KeyProperties.DIGEST_SHA256
setDigests(KeyProperties.DIGEST_SHA256)
并且有效。
希望这对外面的人有帮助。
关于android - 无法在三星 S20、S20+ 和 S20 Ultra 上生成用于生物识别身份验证的 key 对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60676144/