PEM文件中的Java-RSA公钥-Java.lang.NoClassDefFoundError:org/bouncycastle/asn1/x509/SubjectPublicKeyInfo

PEM文件中的Java-RSA公钥-Java.lang.NoClassDefFoundError:org/bouncycastle/asn1/x509/SubjectPublicKeyInfo,java,security,rsa,bouncycastle,java-security,Java,Security,Rsa,Bouncycastle,Java Security,我有一个PEM文件,它是RSA私钥,我正在使用下面的代码读取私钥和公钥: StringReader reader = new StringReader(//pem); PEMReader pemReader = new PEMReader(reader); final KeyPair keyPair = (KeyPair) pemReader.readObject(); pKey = keyPair

我有一个PEM文件,它是RSA私钥,我正在使用下面的代码读取私钥和公钥:

            StringReader reader = new StringReader(//pem);

            PEMReader pemReader = new PEMReader(reader);
            final KeyPair keyPair = (KeyPair) pemReader.readObject();
            pKey = keyPair.getPublic();
            RSAPublicKey rsaPublicKey = (RSAPublicKey) pKey;
            rsaPublicKey.getEncoded();
            Base64.getEncoder().encodeToString(rsaPublicKey.getEncoded()))
  
当作为独立Java运行时,此代码运行良好

但是,当作为Webapplication运行时,我遇到以下错误::

SEVERE: Servlet.service() for servlet MYSERVER threw exception
java.lang.NoClassDefFoundError: org/bouncycastle/asn1/x509/SubjectPublicKeyInfo
        at org.bouncycastle.jce.provider.JCERSAPublicKey.getEncoded(Unknown Source)
库::bcprov-jdk16-143


任何线索???

该错误是因为代码中缺少一些jar依赖项。

该错误是因为代码中缺少一些jar依赖项。

问题是Bouncy Castle需要在Java中注册为有效的加密提供程序。您可以使用如下代码执行此操作:

Security.addProvider(new BouncyCastleProvider());

问题是Bouncy Castle需要在Java中注册为有效的加密提供程序。您可以使用如下代码执行此操作:

Security.addProvider(new BouncyCastleProvider());

或者像Java一样在全球范围内。

不,bc是WEB-INF/lib-infact org.bouncycastle.jce.provider.JCERSAPublicKey和org/bouncycastle/asn1/x509/SubjectPublicKeyInfo的一部分,bc是WEB-INF/lib-infact org.bouncycastle.jce.provider.JCERSAPublicKey的一部分,org/bouncycastle/asn1/x509/SubjectPublicKeyInfo是其一部分与您检查文件或密钥存储的权限相同。。因为web应用程序可能在不同的帐户下运行。我将pem值作为字符串对象加载。我成功地获得了密钥对,但是在提取Base64编码之后..它失败了..请检查您的类路径是否存在重复的BC JAR。e、 g.Web服务器可能有自己的bcprov jar,或者JRE的lib/ext文件夹中可能安装了一个。您是否检查了文件或密钥存储的权限。。因为web应用程序可能在不同的帐户下运行。我将pem值作为字符串对象加载。我成功地获得了密钥对,但是在提取Base64编码之后..它失败了..请检查您的类路径是否存在重复的BC JAR。e、 g.Web服务器可能有自己的bcprov jar,或者在JRE的lib/ext文件夹中安装了一个。我认为在注册提供程序失败时不会出现这种异常。以及在提供的代码片段中没有使用bouncycastle提供程序的任何人。我实际上加载了bouncycastle提供程序..没有给出任何错误-Security.addProvider(new BouncyCastleProvider());我认为您在注册提供商失败时不会出现异常。以及在提供的代码片段中没有使用bouncycastle提供程序的任何人。我实际上加载了bouncycastle提供程序..没有给出任何错误-Security.addProvider(new BouncyCastleProvider());