未提供 Bouncycastle 加密算法

发布于 2024-08-17 06:34:55 字数 1545 浏览 2 评论 0原文

我正在尝试将 BouncyCastle 与 android 一起使用来实现 ECDH 和 EL Gamal。我添加了 bouncycastle jar 文件(bcprov-jdk16-144.jar)并编写了一些适用于我的计算机 jvm 的代码,但是当我尝试将其移植到我的 android 应用程序时,它会抛出:

java.security.NoSuchAlgorithmException: KeyPairGenerator ECDH implementation not found

示例是:

Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

java.security.KeyPairGenerator keyGen = org.bouncycastle.jce.provider.asymmetric.ec.KeyPairGenerator.getInstance("ECDH", "BC");
                ECGenParameterSpec ecSpec = new ECGenParameterSpec("prime192v1");

                keyGen.initialize(ecSpec, SecureRandom.getInstance("SHA1PRNG"));



                KeyPair pair = keyGen.generateKeyPair();
                PublicKey pubk = pair.getPublic();
                PrivateKey prik = pair.getPrivate();

代码 编写了一个简单的程序来查看可用的加密算法,并在我的 android 模拟器和我的计算机 jvm 上运行它,代码是:

Set<Provider.Service> rar = new org.bouncycastle.jce.provider.BouncyCastleProvider().getServices();
    Iterator<Provider.Service> ir = rar.iterator();
    while(ir.hasNext())
        System.out.println(ir.next().getAlgorithm());

在 android 上,我没有得到任何 EC 算法,而在我的计算机上正常运行则很好。

在编译很多充气城堡类时,我还遇到以下两个错误:

01-07 17:17:42.548: INFO/dalvikvm(1054): DexOpt: not resolving ambigeous class 'Lorg/bouncycastle/asn1/ASN1Encodable ;'

01-07 17:17:42.548:DEBUG / dalvikvm(1054):DexOpt:不验证'Lorg / bouncycastle / asn1 / ess / OtherSigningCertificate;':多个定义

我做错了什么?

I'm trying to use BouncyCastle with android to implement ECDH and EL Gamal. I've added the bouncycastle jar file (bcprov-jdk16-144.jar) and written some code that works with my computers jvm however when I try and port it to my android application it throws:

java.security.NoSuchAlgorithmException: KeyPairGenerator ECDH implementation not found

A sample of the code is:

Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

java.security.KeyPairGenerator keyGen = org.bouncycastle.jce.provider.asymmetric.ec.KeyPairGenerator.getInstance("ECDH", "BC");
                ECGenParameterSpec ecSpec = new ECGenParameterSpec("prime192v1");

                keyGen.initialize(ecSpec, SecureRandom.getInstance("SHA1PRNG"));



                KeyPair pair = keyGen.generateKeyPair();
                PublicKey pubk = pair.getPublic();
                PrivateKey prik = pair.getPrivate();

I then wrote a simple program to see what encryption algorithms are available and ran it on my android emulator and on my computers jvm the code was:

Set<Provider.Service> rar = new org.bouncycastle.jce.provider.BouncyCastleProvider().getServices();
    Iterator<Provider.Service> ir = rar.iterator();
    while(ir.hasNext())
        System.out.println(ir.next().getAlgorithm());

On android I do not get any of the EC algorithms while ran normally on my computer it's fine.

I'm also getting the following two errors when compiling for a lot of the bouncy castle classes:

01-07 17:17:42.548: INFO/dalvikvm(1054): DexOpt: not resolving ambiguous class 'Lorg/bouncycastle/asn1/ASN1Encodable;'

01-07 17:17:42.548: DEBUG/dalvikvm(1054): DexOpt: not verifying 'Lorg/bouncycastle/asn1/ess/OtherSigningCertificate;': multiple definitions

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

多彩岁月 2024-08-24 06:34:55

您可能想要 Spongy Castle - 我用 Bouncy Castle 专门针对 Android 制作的重新包装。如此处所述:

http://code.google.com/p/android /issues/detail?id=3280

...不幸的是,Android 平台包含了 Bouncy Castle 的精简版本,这也使得由于类加载器冲突而导致安装库的更新版本变得困难 - 即使您添加了完整的 BC jar,您不会获得添加的附加类。

Spongy Castle 完全替代了 Android 附带的 Bouncy Castle 加密库的残缺版本。为了使其在 Android 上运行,需要进行一些小更改:

  • 所有包名称已从 org.bouncycastle.* 移至 org.spongycastle.* - 因此类加载器不会发生冲突,
  • Java 安全 API 提供程序名称现在为 SC< /strong> 而不是 BC

You probably want Spongy Castle - a repackage I made of Bouncy Castle specifically targeted for Android. As noted here:

http://code.google.com/p/android/issues/detail?id=3280

...the Android platform unfortunately incorporates a cut-down version of Bouncy Castle, which also makes installing an updated version of the libraries difficult due to classloader conflicts - even when you add your full BC jar, you don't get the additional classes you added.

Spongy Castle is a full replacement for the crippled versions of the Bouncy Castle cryptographic libraries which ship with Android. There are a couple of small changes to make it work on Android:

  • all package names have been moved from org.bouncycastle.* to org.spongycastle.* - so no classloader conflicts
  • the Java Security API Provider name is now SC rather than BC
冷血 2024-08-24 06:34:55

我不知道这是否能回答您的问题,但一些 BouncyCastle 库已经包含在 Android SDK 中。也许有关模糊类的错误是因为 BouncyCastle 已包含在模拟器中。

看来您可以通过 javax.crypto.Cipher 类使用它

I don't know if this answers your question, but some of the BouncyCastle libraries are already in the Android SDK. Perhaps the error about ambiguous class is because BouncyCastle is already included in the emulator.

It seems you can use it via the javax.crypto.Cipher class.

错々过的事 2024-08-24 06:34:55

如果您浏览 Android 代码,您会发现并未包含所有 BouncyCastle 功能。
请参阅 libcore/security/src/main/java/org/bouncycastle/jce/provider/BouncyCastleProvider.java

特别是 ECDH 的输出被注释掉,这意味着在编译时它将完全从 android jar 文件中删除。

If you browse the Android code you will see not all BouncyCastle functionalities are included.
see libcore/security/src/main/java/org/bouncycastle/jce/provider/BouncyCastleProvider.java

In particular the output of ECDH is commented out, which means at compilation it will be completely left out from the android jar file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文