来自androidx和加密对象(必须提供加密对象)使用BiometricPrompt的错误

问题描述 投票:1回答:1

我正在Android Studio中制作一个应用程序,该应用程序可以保存您编写的文本并对其进行加密;当然,您也可以解密以读取它。为了保护该应用程序的安全,我正在使用androidx上的Biometrics进行访问。

但是当我使用使用在DECRYPT_MODE中初始化的密码创建的CryptoObject调用Biometric.authenticate时,出现此错误:

java.lang.IllegalArgumentException:必须提供加密对象

我使用KeyGenerator创建一个SecretKey,将UserAuthenticationRequired设置为true并将其存储在AndroidKeyStore中,然后在解密模式下创建一个密码,并希望将其传递给BiometricPrompt.authenticate的调用,以要求身份验证来解密文件。

我在这里这样做:

BiometricPrompt.CryptoObject authenticatedCryptoObject = new BiometricPrompt.CryptoObject(cipher);

// Displays the "log in" prompt.
biometricPrompt.authenticate( promptInfo,authenticatedCryptoObject);

这是我创建和初始化密码的方式:

    keyStore = KeyStore.getInstance("AndroidKeyStore");
    keyStore.load(null);
    KeyStore.SecretKeyEntry secretKeyEntry = (KeyStore.SecretKeyEntry) keyStore.getEntry(KEY_STORE_ALIAS, null);
    secretKey = secretKeyEntry.getSecretKey();
   // cipher = Cipher.getInstance("AES/GCM/NoPadding", "AndroidKeyStore");
    cipher = Cipher.getInstance("AES/GCM/NoPadding", "AndroidKeyStore");
    cipher.init(Cipher.DECRYPT_MODE,secretKey);

我只是无法找到我在Google上遇到的确切错误,因此也许有些人可以帮助我。

java android encryption fingerprint biometrics
1个回答
0
投票

您能否发布所获得的完整堆栈跟踪信息?

© www.soinside.com 2019 - 2024. All rights reserved.