我正在编写一个处理RSA密钥的android程序。私钥(长度2048)是从字节数组导入的(不是由设备生成的)。如果我使用Android Studio Emulator API 31,该密钥可以毫无问题地使用。但是在Pixel 3硬件API 31上,有一个例外。原因是什么?
----- DEVICE -----
Brand: google
Device: blueline
Model: Pixel 3
ID: SP1A.210812.016.C2
Product: blueline
----- ANDROID OS -----
Android SDK: 31
Android release: 12
Android incremental: 8618562
堆栈跟踪:
03-22 22:46:03.611 23770 23770 W System.err: java.security.InvalidKeyException: Size of key not known
03-22 22:46:03.611 23770 23770 W System.err: at android.security.keystore2.AndroidKeyStoreRSACipherSpi.initKey(AndroidKeyStoreRSACipherSpi.java:451)
03-22 22:46:03.611 23770 23770 W System.err: at android.security.keystore2.AndroidKeyStoreCipherSpiBase.init(AndroidKeyStoreCipherSpiBase.java:256)
03-22 22:46:03.611 23770 23770 W System.err: at android.security.keystore2.AndroidKeyStoreCipherSpiBase.engineInit(AndroidKeyStoreCipherSpiBase.java:168)
03-22 22:46:03.611 23770 23770 W System.err: at javax.crypto.Cipher.tryTransformWithProvider(Cipher.java:2985)
03-22 22:46:03.611 23770 23770 W System.err: at javax.crypto.Cipher.tryCombinations(Cipher.java:2892)
03-22 22:46:03.611 23770 23770 W System.err: at javax.crypto.Cipher$SpiAndProviderUpdater.updateAndGetSpiAndProvider(Cipher.java:2797)
03-22 22:46:03.611 23770 23770 W System.err: at javax.crypto.Cipher.chooseProvider(Cipher.java:774)
03-22 22:46:03.611 23770 23770 W System.err: at javax.crypto.Cipher.init(Cipher.java:1144)
03-22 22:46:03.611 23770 23770 W System.err: at javax.crypto.Cipher.init(Cipher.java:1085)
1条答案
按热度按时间pzfprimi1#
转到
AndroidKeyStoreRSACipherSpi
的API级别31源代码(如上所示),并在它抛出InvalidKeyException
并显示消息“Key的大小未知”之前设置断点。比较Pixel 3和模拟器上的运行。检查其中有什么区别。