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)
バウンシーキャッスル 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 ライブラリを放棄することに決めました.私の場合、これはオプションではありません.
誰も手がかりを持っていますか?