我使用BouncyCastle的庫時得到一個奇怪的錯誤:安卓:7的CyanogenMod(Android 2.3的)+ BouncyCastle的加密庫:IllegalAccessError
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;
}
有趣的是:它完美的unmodded Android 2.2手機上,但我得到我的手機上這個錯誤,用的CyanogenMod 7.0.2.1改裝成( Android 2.3?)。 HTC Desire都是改裝的和未改裝的手機。
該項目是針對Android 2.2庫建立的。這是問題嗎?如果是這樣,我應該創建不同的構建項目來區分這些版本嗎?這將是非常不愉快的....
我已經在這裏檢查了一個類似的問題:IllegalAccessError with Android and BouncyCastle但他們決定放棄bouncycastle庫,在我的情況是不是一個選項。
有沒有人有線索?
謝謝,我會嘗試 – Dirk 2011-04-28 11:58:35