java.lang.ClassNotFoundException:org.bouncycastle.jcajce.provider.asymmetric.rsa.CipherSpi $ NoPadding

时间:2018-07-20 10:55:04

标签: java rsa bouncycastle

尝试使用.cer加密。它可以在本地系统上工作,但是当我投入生产时会出错。 我在Live服务器上有bcprov-jdk15on-158.jar文件。

源代码

public static byte[] encryptUsingPublicKey(byte[] data, PublicKey publicKey) throws IOException, GeneralSecurityException {
    Cipher pkCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding", "BC");//Here iam Getting Error
    pkCipher.init(Cipher.ENCRYPT_MODE, publicKey);
    byte[] encSessionKey = pkCipher.doFinal(data);
    return encSessionKey;
}

错误堆栈跟踪

        INFO: Illegal access: this web application instance has been stopped already.  Could not load org.bouncycastle.jca.provider.asymmetric.rsa.CipherSpi$NoPadding.  The eventual following stack trace is caused by an error thrown forbugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functio impact.
java.lang.IllegalStateException
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1777)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1735)
        at java.security.Provider$Service.getImplClass(Provider.java:1636)
        at java.security.Provider$Service.newInstance(Provider.java:1592)
        at javax.crypto.Cipher.getInstance(Cipher.java:668)
        at javax.crypto.Cipher.getInstance(Cipher.java:595)
        at in.gov.cgg.struts.utilities.common.TAEncrypter.encryptUsingPublicKey(TAEncrypter.java:134)
        at in.gov.cgg.struts.utilities.common.TAEncrypter.EncryptRequest(TAEncrypter.java:57)

       ...

java.security.NoSuchAlgorithmException: No such algorithm: RSA/ECB/PKCS1Padding
        at javax.crypto.Cipher.getInstance(Cipher.java:687)
        at javax.crypto.Cipher.getInstance(Cipher.java:595)
        at in.gov.cgg.struts.utilities.common.TAEncrypter.encryptUsingPublicKey(TAEncrypter.java:134)
        at in.gov.cgg.struts.utilities.common.TAEncrypter.EncryptRequest(TAEncrypter.java:57)
        at in.gov.cgg.struts.actions.RequestHandlerAction.unspecified(RequestHandlerAction.java:78)
        at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:256)
        at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
       ....
Caused by: java.security.NoSuchAlgorithmException: class configured for Cipher (provider: BC) cannot be found.
        at java.security.Provider$Service.getImplClass(Provider.java:1649)
        at java.security.Provider$Service.newInstance(Provider.java:1592)
        at javax.crypto.Cipher.getInstance(Cipher.java:668)
        ... 32 more
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jcajce.provider.asymmetric.rsa.CipherSpi$NoPadding
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1892)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1735)
        at java.security.Provider$Service.getImplClass(Provider.java:1636)
        ... 34 more

1 个答案:

答案 0 :(得分:0)

git remote rm heroku在您的java.lang.ClassNotFoundException中无法使用该类时生成。检查classpath是否包含预期的jar。即使它在服务器上,也可能不包含在classpth中。

没有其他原因classpath