安卓:7的CyanogenMod(安卓2.3)+ BouncyCastle的加密库:IllegalAccessError [英] Android: CyanogenMod 7 (Android 2.3) + BouncyCastle encryption libraries: IllegalAccessError

查看:207
本文介绍了安卓:7的CyanogenMod(安卓2.3)+ BouncyCastle的加密库:IllegalAccessError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的BouncyCastle的库时得到一个奇怪的错误:

I'm getting a strange error when using bouncycastle libraries:

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项目。

I've added the bouncycastle jar file (bcprov145.jar) to the eclipse project.

这是产生此异常的code是:

The code that generated this exception is:

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;
}

有趣的是:(?安卓2.3),它完美的unmodded Android 2.2手机上,但我得到我的手机上这个错误,用的CyanogenMod 7.0.2.1改装成。无论是改装成和unmodded手机是HTC Desire的。

The funny thing is: It works perfectly on an unmodded Android 2.2 phone, but I get this error on my phone, modded with CyanogenMod 7.0.2.1 (Android 2.3?). Both the modded and the unmodded phone are HTC Desire.

该项目建造针对Android 2.2的库。那是什么问题?如果是,我应该创建不同的构建项目来区分这些版本?这将是非常不愉快......

The project is builded against Android 2.2 libraries. Is that the problem? If it is, should I create different build-projects to differentiate on these versions? That would be very unpleasant....

我已经签出了类似的问题在这里:<一href=\"http://stackoverflow.com/questions/5659965/illegalaccesserror-with-android-and-bouncycastle\">IllegalAccessError Android和BouncyCastle的但他们决定放弃BouncyCastle的库,这在我的情况不是一个选项。

I've already checked out a similar issue here: IllegalAccessError with Android and BouncyCastle but they decided to abandon the bouncycastle libs, which in my case is not an option.

有没有人有线索?

推荐答案

该充气城堡军团是Android固件的一部分,但不是SDK的一部分。你不能可靠地添加自己实施的JAR。无论是通过 javax.crypto中 API使用的城堡,或者发现你可以使用另一个加密库。

The Legion of the Bouncy Castle is part of the Android firmware, but not part of the SDK. You cannot reliably add your own implementation of the JAR. Either use the Castle through the javax.crypto APIs, or find another crypto library that you can use.

这篇关于安卓:7的CyanogenMod(安卓2.3)+ BouncyCastle的加密库:IllegalAccessError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆