Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 删除指纹不会触发Fingerprnt身份验证的InvalidKeyException_Android_Android Fingerprint Api - Fatal编程技术网

Android 删除指纹不会触发Fingerprnt身份验证的InvalidKeyException

Android 删除指纹不会触发Fingerprnt身份验证的InvalidKeyException,android,android-fingerprint-api,Android,Android Fingerprint Api,我面临指纹认证的问题,事实上,我已经在我的应用程序中集成了指纹认证,除了一个案例外,工作正常 我已经在我的设备中设置了两个指纹,在使用指纹密钥初始化KeyGenerator后,我已经从设备中删除了一个指纹,然后返回到我的应用程序并执行指纹验证。它工作正常。我不知道为什么它不会像添加指纹一样触发InvalidKeyException这是预期的行为还是操作系统中的任何错误? 设备详情如下: 设备:像素 OS:Android 8.0 我的实现代码如下: protected void generateK

我面临指纹认证的问题,事实上,我已经在我的应用程序中集成了指纹认证,除了一个案例外,工作正常

我已经在我的设备中设置了两个指纹,在使用指纹密钥初始化
KeyGenerator
后,我已经从设备中删除了一个指纹,然后返回到我的应用程序并执行指纹验证。它工作正常。我不知道为什么它不会像添加指纹一样触发
InvalidKeyException
这是预期的行为还是操作系统中的任何错误?

设备详情如下:

设备:像素

OS:Android 8.0

我的实现代码如下:

protected void generateKey() {
       try {
           keyStore = KeyStore.getInstance("AndroidKeyStore");
       } catch (Exception e) {
           e.printStackTrace();
       }


       KeyGenerator keyGenerator;
       try {
           keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
       } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
           throw new RuntimeException("Failed to get KeyGenerator instance", e);
       }


       try {
           keyStore.load(null);
           keyGenerator.init(new
                   KeyGenParameterSpec.Builder(KEY_NAME,
                   KeyProperties.PURPOSE_ENCRYPT |
                           KeyProperties.PURPOSE_DECRYPT)
                   .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
                   .setUserAuthenticationRequired(true)
                   .setEncryptionPaddings(
                           KeyProperties.ENCRYPTION_PADDING_PKCS7)
                   .build());
           keyGenerator.generateKey();
       } catch (NoSuchAlgorithmException |
               InvalidAlgorithmParameterException
               | CertificateException | IOException e) {
           throw new RuntimeException(e);
       }
   }

 public boolean cipherInit() {
       try {
           cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7);
       } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
           throw new RuntimeException("Failed to get Cipher", e);
       }


       try {
           keyStore.load(null);
           SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME,
                   null);
           cipher.init(Cipher.ENCRYPT_MODE, key);
           return true;
       } catch (KeyPermanentlyInvalidatedException e) {
           return false;
       } catch (KeyStoreException | CertificateException | UnrecoverableKeyException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
           throw new RuntimeException("Failed to init Cipher", e);
       }
   }
}

我已经尝试了几篇文章(,),但没有任何东西能帮我摆脱它。

你的代码没有严格地与指纹绑定。它所具有的一切都有一定的关联性:

setUserAuthenticationRequired(true)
也就是说,您在
AndroidKeyStore
中创建的密钥需要用户身份验证。它没有提到指纹

如果用户已注册指纹,则用户可以使用指纹进行身份验证以使用此密钥。这将适用于用户注册的任何指纹,在您的情况下,您仍然拥有注册的指纹(即使在用户删除第二个指纹之后)。此外,用户不必使用指纹进行身份验证——如果愿意,他们可以使用自己的密码短语、PIN或模式

这是预期的行为还是操作系统中的任何错误


这是预期的行为。

非常感谢您提供的简短细节,有没有办法识别指纹删除?@SathishKumar:我不这么认为。好的,谢谢。“此外,用户不必使用指纹进行身份验证-如果他们愿意,他们可以使用他们的密码、PIN或模式。”除非使用
setUserAuthenticationValidityDurationSeconds
在给定的时间范围内允许每次身份验证多次使用密钥。否则,文档会声明“当前,唯一的授权方式是指纹认证”。不正确,当setUserAuthenticationRequired设置为true时,密钥库密钥将无效,密钥将无法再使用。请参阅文件。