java - 安卓.security.KeyStoreException : User authentication required after upgrade to android 8

标签 java android security

在 android 8 上更新后,当我尝试创建新 key 以便在指纹身份验证后使用它时,我收到 android.security.KeyStoreException: User authentication required 。 在更新到 8 之前,它按预期工作。 这并非在所有设备上都会发生。

  mKeyStore.load(null);

 KeyGenParameterSpec spec = new KeyGenParameterSpec.Builder(
                    alias,
                    KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT | KeyProperties.PURPOSE_SIGN | KeyProperties.PURPOSE_VERIFY)
                    .setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA512)
                    .setSignaturePaddings(KeyProperties.SIGNATURE_PADDING_RSA_PKCS1)
                    .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1)
                    .setBlockModes(KeyProperties.BLOCK_MODE_ECB)
                    .setUserAuthenticationRequired(userAuthenticationRequired) 
                    .setKeyValidityEnd(calendar.getTime())
                    .setKeySize(keysize)
                    .build();
mKeyPairGenerator.initialize(spec);
 KeyPair keyPair = mKeyPairGenerator.generateKeyPair();//this is the line I'm getting the keystore exception

最佳答案

我们将此问题缩小到 S9 Android 8 设备未使用 PIN、图案或密码进行保护。

一个解决方案是在 generateKeyPair 周围的 try catch block 中添加一个 ProviderException 并在那里处理它。

或者,您可以使用 KeyguardManager.isKeyguardSecure() 来防止 key 生成。

关于java - 安卓.security.KeyStoreException : User authentication required after upgrade to android 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50050247/

相关文章:

java - 如何通过单击菜单项来更改布局?

java - RESTful安全授权

java - 将图像上传到 firebase 存储需要权限吗?如何?

java - 如何在抽象类下进行一次性操作

android - 以编程方式获取布局的高度和宽度

java - 如何在 Anko ViewPager 上知道当前点击的页面

javascript - 是否可以使用 JavaScript + Cookie 来欺骗 session ?

java - 对其他应用程序和类隐藏变量

java - 为 JAX-WS 客户端设置 SSL

android - 在手机版android中打开google play store的链接