【发布时间】:2011-04-28 09:14:58
【问题描述】:
我在使用 bouncycastle 库时遇到了一个奇怪的错误:
ERROR/AndroidRuntime(1226): FATAL EXCEPTION: Thread-10
ERROR/AndroidRuntime(1226): java.lang.IllegalAccessError: tried to access class org.bouncycastle.crypto.engines.RSACoreEngine from class org.bouncycastle.crypto.engines.RSAEngine
ERROR/AndroidRuntime(1226): at org.bouncycastle.crypto.engines.RSAEngine.init(Unknown Source)
ERROR/AndroidRuntime(1226): at org.bouncycastle.crypto.encodings.PKCS1Encoding.init(PKCS1Encoding.java:90)
我已将 bouncycastle jar 文件 (bcprov145.jar) 添加到 eclipse 项目中。
产生这个异常的代码是:
public int encrypt(byte[] source, int sourceLength, byte[] destination,
int destinationLength) throws CryptoError
{
int offset = 0;
byte[] encrypted;
org.bouncycastle.crypto.AsymmetricBlockCipher engine =
new org.bouncycastle.crypto.engines.RSAEngine();
engine = new org.bouncycastle.crypto.encodings.PKCS1Encoding(engine);
BigInteger mod = publicKey.getModulus();
BigInteger exp = publicKey.getPublicExponent();
org.bouncycastle.crypto.params.RSAKeyParameters keyParams =
new org.bouncycastle.crypto.params.RSAKeyParameters(false, mod, exp);
//When running the following line, the sh*t hits the fan....
engine.init(true, keyParams);
try
{
encrypted = engine.processBlock(source, offset, source.length);
}
catch (org.bouncycastle.crypto.InvalidCipherTextException e)
{
throw new CryptoError(e);
}
int length = Math.min(encrypted.length, destinationLength);
BufferTools.copyByteArray(encrypted, destination, length);
return length;
}
有趣的是:它在未修改的 Android 2.2 手机上完美运行,但我的手机上出现此错误,修改了 CyanogenMod 7.0.2.1(Android 2.3?)。改装和未改装的手机都是 HTC Desire。
该项目是针对 Android 2.2 库构建的。那是问题吗?如果是,我应该创建不同的构建项目来区分这些版本吗?那会很不愉快....
我已经在这里检查了一个类似的问题:IllegalAccessError with Android and BouncyCastle 但他们决定放弃 bouncycastle 库,在我的情况下这不是一个选项。
有人知道吗?
【问题讨论】:
标签: android encryption bouncycastle android-sdk-2.3 cyanogenmod