bouncycastle提供程序找不到算法所需的类 [英] bouncycastle provider can't find classes needed for algorithm

查看:436
本文介绍了bouncycastle提供程序找不到算法所需的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用bouncycastle通过公用密钥对文件进行加密。
我已经通过编程方式注册了提供程序:

I'm trying to use bouncycastle to encrypt a file using a public key. I've registered the provider programatically:

Security.addProvider(new BouncyCastleProvider());

我成功创建了公钥对象。

I created the public key object successfully.

当我使用PGPEncryptedDataGenerator和密钥对文件进行加密时,我得到ClassNotFound异常。

when i get to encrypting the file using a PGPEncryptedDataGenerator and the key I get a ClassNotFound exception.

似乎提供程序在运行时找不到此类。我肯定知道我有它的罐子……

It seems the provider can't find this class at runtime, though I know for sure I have its jar...

我正在tomcat上运行我的应用程序。
使用Maven处理依赖关系-我放入的充气城堡罐子是bcpg,bcprov,bcmail,bctsp。
我尝试同时使用1.4和1.6版本,但均未成功。
我使用了maven插件中的依赖关系层次结构进行eclipse和pom中的排除,以确保我的项目中没有多个版本的bouncycastle。

I'm running my app on tomcat. Using maven to handle dependencies - the bouncy castle jars I put are bcpg, bcprov, bcmail, bctsp. I tried using both the 1.4 and the 1.6 versions without success. I used the "dependency hierarchy" in maven plugin for eclipse and exclusions in the pom to make sure that there are no multiple versions of bouncycastle in my project.

这是堆栈跟踪:

org.bouncycastle.openpgp.PGPException: exception encrypting session key
        at org.bouncycastle.openpgp.PGPEncryptedDataGenerator.open(Unknown Source)
        at org.bouncycastle.openpgp.PGPEncryptedDataGenerator.open(Unknown Source)
.....(web application stack trace and uninteresting stuff).....
Caused by: java.security.NoSuchAlgorithmException: No such algorithm: ElGamal/ECB/PKCS1Padding
        at javax.crypto.Cipher.getInstance(DashoA13*..)
        at org.bouncycastle.openpgp.PGPEncryptedDataGenerator$PubMethod.addSessionInfo(Unknown Source)
        ... 42 more
Caused by: java.security.NoSuchAlgorithmException: class configured for Cipher(provider: BC)cannot be found.
        at java.security.Provider$Service.getImplClass(Provider.java:1268)
        at java.security.Provider$Service.newInstance(Provider.java:1220)
        ... 44 more
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.JCEElGamalCipher$NoPadding
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
        at java.security.Provider$Service.getImplClass(Provider.java:1262)


推荐答案

您遇到了BouncyCastle Security提供程序安装问题,您要么需要

You have a BouncyCastle Security provider installation problem, you need to either


  • 将BouncyCastle添加到JRE / JDK $ JAVA_HOME / jre / lib / security / java.security 文件中提供程序(请确保将其添加到运行时使用的JRE中,例如,如果您安装了多个JRE / JDK)

  • Add BouncyCastle to the JRE/JDK $JAVA_HOME/jre/lib/security/java.security file as a provider (be sure that you add it to the JRE you use when running, eg. if you have multiple JRE's/JDK's installed)

例如

security.provider.2=org.bouncycastle.jce.provider.BouncyCastleProvider

(并对其下方的安全提供程序重新编号-不要将其设置为最高优先级提供程序)。

(and renumber the security providers below it - don't put it as the highest priority provider).


  • ,或者您可以像上面一样尝试以编程方式添加BouncyCastle,但在这种情况下,安全策略 $ JAVA_HOME / jre / lib / security / java.policy 应该是无限(您可以从Java主页下载无限策略文件)。

  • or you can add BouncyCastle programmatically, as you were trying to do above, but in this case the security policy $JAVA_HOME/jre/lib/security/java.policy should be "unlimited" (you can probably download an unlimited policy file from the Java homepage).

这篇关于bouncycastle提供程序找不到算法所需的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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