gpg加解密异常
在本地windows电脑和开发环境(linux) ,都不报错,但是在测试环境(linux) 上报错。
报错信息
org.bouncycastle.openpgp.PGPException: Exception creating cipher at org.bouncycastle.openpgp.PGPEncryptedDataGenerator.open(Unknown Source) at org.bouncycastle.openpgp.PGPEncryptedDataGenerator.open(Unknown Source) at com.bfs.pgp.Encrypt.encrypt(Encrypt.java:206) at com.bfs.pgp.Encrypt.getEncryptedString(Encrypt.java:105) at org.apache.jsp.webapps.xxx.pages.xxx.XXXStart_jsp.getCryptedValue(XXXStart_jsp.java:26) at org.apache.jsp.webapps.xxx.pages.xxx.XXXStart_jsp._jspService(XXXStart_jsp.java:158) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:722) Caused by: org.bouncycastle.openpgp.PGPException: cannot create cipher: No such algorithm: IDEA/OpenPGPCFB/NoPadding at org.bouncycastle.openpgp.operator.jcajce.OperatorHelper.createCipher(Unknown Source) at org.bouncycastle.openpgp.operator.jcajce.OperatorHelper.createStreamCipher(Unknown Source) at org.bouncycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder$MyPGPDataEncryptor.<init>(Unknown Source) at org.bouncycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder.build(Unknown Source) ... 24 more Caused by: java.security.NoSuchAlgorithmException: No such algorithm: IDEA/OpenPGPCFB/NoPadding at javax.crypto.Cipher.getInstance(Cipher.java:673) at javax.crypto.Cipher.getInstance(Cipher.java:580) at org.bouncycastle.jcajce.NamedJcaJceHelper.createCipher(Unknown Source) ... 28 more java.lang.NullPointerException at java.io.ByteArrayInputStream.<init>(ByteArrayInputStream.java:106) at sun.misc.CharacterEncoder.encode(CharacterEncoder.java:188) at com.bfs.pgp.Encrypt.getEncryptString(Encrypt.java:237) at com.bfs.pgp.Encrypt.getEncryptedString(Encrypt.java:106) at org.apache.jsp.webapps.xxxPayment.pages.xxxx.XXXStart_jsp.getCryptedValue(XXXStart_jsp.java:26) at org.apache.jsp.webapps.xxxPayment.pages.xxxx.XXXStart_jsp._jspService(XXXStart_jsp.java:158) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:722)
原因:
默认自带的policy.jar不支持gpg加密的功能。 需要替换jar
方法1: 修改java.security
先找到java的安装位置
windows下查看版本:(默认安装路径安装就不需要去配环境变量了)
1 java -version
windows下查看安装路径:
1 java -verbose
找到 jre/lib/security/java.security
检查是否有写入的权限为(644)没有的话授权
vi jre/lib/security/java.security
新增
security.provider.10=org.bouncycastle.jce.provider.BouncyCastleProvider
保存完成在把文件的权限改为(444)
2、方法2
替换
jre/lib/security/policy/limited/local_policy.jar
jre/lib/security/policy/limited/US_export_policy.jar
并修改为权限(644)
来源
BouncyCastle Exception while creating cipher