微信开发中,使用密文消息进行解密时,报错如下:
1 java.security.InvalidKeyException: Illegal key size 2 at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1024) 3 at javax.crypto.Cipher.implInit(Cipher.java:790) 4 at javax.crypto.Cipher.chooseProvider(Cipher.java:849) 5 at javax.crypto.Cipher.init(Cipher.java:1348) 6 at javax.crypto.Cipher.init(Cipher.java:1282) 7 at cn.ac.bird.wx.util.WXBizMsgCrypt.decrypt(WXBizMsgCrypt.java:158) 8 at cn.ac.bird.wx.util.WXBizMsgCrypt.decryptMsg(WXBizMsgCrypt.java:262) 9 at cn.ac.bird.wx.servlet.CoreServlet.doPost(CoreServlet.java:73) 10 at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) 11 at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 12 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 13 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 14 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) 15 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) 16 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 17 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) 18 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) 19 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) 20 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 21 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 22 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023) 23 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) 24 at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852) 25 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 26 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 27 at java.lang.Thread.run(Thread.java:724)
Google到问题原因,链接地址如下:
http://stackoverflow.com/questions/6481627/java-security-illegal-key-size-or-default-parameters
解决方法:
http://www.oracle.com/technetwork/java/embedded/embedded-se/downloads/jce-7-download-432124.html
官网找到响应版本的jdk文件,进行相应替换即可
把里面的两个jar包:local_policy.jar 和 US_export_policy.jar 替换掉原来安装目录C:Program FilesJavajre7libsecurity 下的两个jar包接可以了
然后就重新运行程序,ok