我正在尝试用 tomcat 实现充气城堡,但我得到了 ClassNotFound Exception

Posted

技术标签:

【中文标题】我正在尝试用 tomcat 实现充气城堡,但我得到了 ClassNotFound Exception【英文标题】:I am trying to implement bouncy castle with tomcat and I am getting ClassNotFound Exception 【发布时间】:2015-12-21 03:58:43 【问题描述】:

我已经尝试了一切: 我已按照本教程进行操作:How to create a BKS (BouncyCastle) format Java Keystore that contains a client certificate chain

我仍然收到 Class not found 异常请帮助。

SEVERE: Failed to initialize connector [Connector[HTTP/1.1-8443]]
org.apache.catalina.LifecycleException: Failed to initialize component [Connector[HTTP/1.1-8443]]
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)
    at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:821)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:642)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:667)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:253)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:427)
Caused by: org.apache.catalina.LifecycleException: Protocol handler initialization failed
    at org.apache.catalina.connector.Connector.initInternal(Connector.java:980)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    ... 12 more
Caused by: java.lang.ClassNotFoundException: Error loading SSL Implementation org.bouncycastle.jce.provider.BouncyCastleProvider :java.lang.ClassCastException: org.bouncycastle.jce.provider.BouncyCastleProvider cannot be cast to org.apache.tomcat.util.net.SSLImplementation
    at org.apache.tomcat.util.net.SSLImplementation.getInstance(SSLImplementation.java:75)
    at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:118)
    at org.apache.catalina.connector.Connector.initInternal(Connector.java:978)
    ... 13 more

这是我的 java.security 中的提供程序:

security.provider.1=sun.security.provider.Sun
security.provider.2=org.bouncycastle.jce.provider.BouncyCastleProvider
security.provider.3=sun.security.rsa.SunRsaSign
security.provider.4=sun.security.ec.SunEC
security.provider.5=com.sun.net.ssl.internal.ssl.Provider
security.provider.6=com.sun.crypto.provider.SunJCE
security.provider.7=sun.security.jgss.SunProvider
security.provider.8=com.sun.security.sasl.Provider
security.provider.9=org.jcp.xml.dsig.internal.dom.XMLDSigRI
security.provider.10=sun.security.smartcardio.SunPCSC
security.provider.11=apple.security.AppleProvider

【问题讨论】:

这个问题可能重复吗? ***.com/questions/19505042/… Rob 老兄,我已经锁定了这个问题,但它并没有解决我的问题 我想我不会使用 Bouncy Castle 而是使用 Java 附带的标准密钥库 我终于重新阅读了堆栈跟踪。 ClassNotFoundException 非常具有误导性。请注意,实际上根本原因是 ClassCastException。因此,类路径甚至 java.security 的配置都不是问题。相反,问题必须与sslImplementationName 设置有关。 好的,那我该怎么办,你有什么解决办法吗? 【参考方案1】:

从您包含的链接尝试替换

Security.addProvider(new BouncyCastleProvider());

通过

Security.insertProviderAt(new BouncyCastleProvider(), 1); 
//  The position is 1-based, that is, 1 is most preferred, followed by 2, and so on.

确保 BC 优于 Sun Provider

【讨论】:

以上是关于我正在尝试用 tomcat 实现充气城堡,但我得到了 ClassNotFound Exception的主要内容,如果未能解决你的问题,请参考以下文章

充气城堡 C# 中的 PBKDF2

X509 RSA充气城堡标志数据和验证

c#充气城堡验证签名上的InvalidCastException

如何在netbeans java中使用充气城堡(DES)加密和解密文件?

验证充气城堡上的 javacard 签名 ALG_ECDSA_SHA

使用充气城堡验证签名