无法加载[org.bouncycastle.jcajce.provider.digest.GOST3411 $ Mappings]

时间:2019-07-01 13:25:09

标签: java spring tomcat8 bouncycastle

我正在使用tomcat8服务器,.bouncycastle进行文档签名。 我的服务器上已在运行一个war文件。当我为第二个项目部署了新的war文件时,则获取以下异常。

我已经点击并尝试了stackoverflow上的每个链接,但没有运气

  

org.apache。 catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading   非法访问:此Web应用程序实例已停止   已经。不能加载   [org.bouncycastle.jcajce.provider.digest.GOST3411 $ Mappings]。的   以下堆栈跟踪被抛出以用于调试以及   尝试终止导致非法访问的线程。   java.lang.IllegalStateException:非法访问:此Web应用程序   实例已经停止。无法加载

 public static void xmlSigner(File xmlFile,String pfxFilePath){
    try{
            File pfxFile=new File(pfxFilePath);
            Security.addProvider(new BouncyCastleProvider());
            log.info("Above key store ");
            KeyStore keyStore = KeyStore.getInstance("pkcs12", "BC");
            log.info("below key store ");
            keyStore.load(new FileInputStream(pfxFile),password.toCharArray());
            log.info("load pfx file key store ");
            String alias = (String) keyStore.aliases().nextElement();
            PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
            Certificate[] certificateChain = keyStore.getCertificateChain(alias);
            X509Certificate publickeyCertificate = (X509Certificate) certificateChain[certificateChain.length - 1];
            //log.info("privateKey : " + privateKey);
            //log.info("xmlSigner : " + xmlFile);
            log.info("SignerClient - Above Sign and Zip");
            SignerUtil.signAndzipFile(xmlFile, privateKey, publickeyCertificate);
            log.info("Successfully Signed");
        }
        catch(Exception xmlSignerException){
            log.error("xmlSigner : ", xmlSignerException);
            xmlSignerException.printStackTrace();

        }

   }

我在下面的行中遇到异常

KeyStore keyStore = KeyStore.getInstance("pkcs12", "BC");

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,Tomcat重新启动已解决了该问题。

keystore = KeyStore.getInstance("PKCS12", "BC");
// java.security.KeyStoreException: PKCS12 not found
Caused by: java.security.NoSuchAlgorithmException: class configured for KeyStore (provider: BC) cannot be found.
    at java.security.Provider$Service.getImplClass(Provider.java:1649)
    at java.security.Provider$Service.newInstance(Provider.java:1592)
    at sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
    at sun.security.jca.GetInstance.getInstance(GetInstance.java:206)
    at java.security.Security.getImpl(Security.java:698)
    at java.security.KeyStore.getInstance(KeyStore.java:896)
    ... 11 more
Caused by: java.lang.ClassNotFoundException: Illegal access: this web application instance has been stopped already. Could not load [org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi$BCPKCS12KeyStore]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
    at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1354)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1211)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1172)
    at java.security.Provider$Service.getImplClass(Provider.java:1636)
    ... 16 more
Caused by: java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi$BCPKCS12KeyStore]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
    at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1364)
    at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1352)
    ... 19 more

答案 1 :(得分:0)

请首先检查org.bouncycastle是否具有多个版本。保留一个版本,如果使用tomcat,请重新启动tomcat。