【发布时间】:2015-08-07 02:48:46
【问题描述】:
我在使用 RSA 解密时出错。 该代码适用于 android 4.4 kit kat,但相同的应用程序不适用于 android 5.0 lollipop。
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(new BigInteger(modulusBytes), new BigInteger(exponentBytes));
RSAPublicKey publicKey = (RSAPublicKey) keyFactory.generatePublic(pubKeySpec);
byte[] decrypted = null;
try {
// get an RSA cipher object and print the provider
final Cipher cipher = Cipher.getInstance("RSA/None/NoPadding");
// decrypt the text using the public key
cipher.init(Cipher.DECRYPT_MODE, publicKey);
decrypted = cipher.doFinal(area_fissa_byte);
} catch (Exception ex) {
ex.printStackTrace();
Log.d("error","error");
}
错误是:java.security.SignatureException: error:04067084:rsaroutines:RSA_EAY_PUBLIC_DECRYPT:data too large for modules。
我的sdk目标是:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" /> 适用于安卓 4.4
你知道是什么问题吗?
编辑: 我注意到我有 2 个不同长度的不同公钥!!! Android 5:我有 382/383 位(太小) Android 4.4:我有 384 位(好的)
EDIT2: 我发现 TLS/SSL 与 android 5.0 存在差异:https://developer.android.com/about/versions/android-5.0-changes.html 但我不知道如何解决这个问题。
【问题讨论】:
-
我在某处读到 SSL 初始化在某些 android 旧版本上不正确,并且已修复,所以这可能以某种方式相关吗?
-
@Yazan 我不知道。我发现可能的提供程序是不同的(Provider[] providers = Security.getProviders();),但应用程序始终使用“AndroidOpenSSL”。不同之处在于,对于 android 4.4,提供程序的大小是 127,对于 android 5,是 143。然后我有两个不同的密钥大小。你知道是否有一种方法可以在 android 5 上使用与 android 4.4 相同的 keyfactory?
标签: ssl rsa android-5.0-lollipop android-4.4-kitkat public-key