项目中加密算法时报错:Illegal key size or default parameters
在java中可能会面临需要加密 解密传输一些数据信息, 最近我就在项目中用到加密算法AES, 然而在启动项目时,给我报错了
cn.hnisi.wx.core.exception.AppException: java.security.InvalidKeyException: Illegal key size or default parameters
at cn.hnisi.wx.server.validateface.ValidateFaceService.getDetectInfo(ValidateFaceService.java:404) ~[classes/:na]
at cn.hnisi.wx.server.validateface.ValidateFaceService.saveTokenDetail(ValidateFaceService.java:88) ~[classes/:na]
at cn.hnisi.wx.server.validateface.ValidateFaceService$$FastClassBySpringCGLIB$$26e78a3d.invoke(<generated>) ~[classes/:na]at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]
.
.
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor$$Lambda$450/1438104724.proceedWithInvocation(Unknown Source) ~[na:na]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) ~[spring-tx-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) ~[spring-tx-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_45]
.
.
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]
经过查阅资料
http://www.cnblogs.com/AloneSword/p/3487809.html
发现 我们jdk 或jre\lib\security目录 下, 需要两个保密的jar文件
Oracle在其官方网站上提供了无政策限制权限文件(Unlimited Strength Jurisdiction Policy Files),我们只需要将其部署在JRE环境中,就可以解决限制问题。
下载地址:
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-java-plat-419418.html
把里面的两个jar包:local_policy.jar 和 US_export_policy.jar 替换掉原来安装目录jdk中或者jre中的\lib\security 下的两个jar包接可以了