java.lang.IllegalArgumentExcepti
Android 指纹相关 配置CryptoObject 参数时
送入以下Cipher对象
String alg = "AES"; //也可能是其他算法
Cipher cipher = Cipher.getInstance(alg);
KeyGenerator generator = KeyGenerator.getInstance(alg);
SecretKey key = generator.generateKey();
cipher.init(Cipher.ENCRYPT_MODE, key);
再调用指纹验证接口 BiometricPrompt.authenticate(cipher, xx,xx,xx);
抛出如下异常:
java.lang.IllegalArgumentException: Crypto primitive not backed by AndroidKeyStore provider: javax.crypto.Cipher@e5e2725, spi: com.android.org.bouncycastle.jcajce.provider.symmetric.AES$ECB@9a220fa
其实是Key 和Cipher 类型不对, 未指定正确的provider, 导致构造了android-bc库的加密相关对象
指定方式参考以下代码
String alg = "AES"; //也可能是其他算法
Cipher cipher = Cipher.getInstance(alg, "SunJCE");
KeyGenerator generator = KeyGenerator.getInstance(alg, "SunJCE");
SecretKey key = generator.generateKey();
cipher.init(Cipher.ENCRYPT_MODE, key);