java项目报错 illegal key size

2022.05.11.解决java项目遇到的 java.security.InvalidKeyException: Illegal key size 报错

java.security.InvalidKeyException: Illegal key size
        at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1039)
        at javax.crypto.Cipher.implInit(Cipher.java:805)
        at javax.crypto.Cipher.chooseProvider(Cipher.java:864)
        at javax.crypto.Cipher.init(Cipher.java:1396)
        at javax.crypto.Cipher.init(Cipher.java:1327)
        at com.teradata.data.util.AesUtils.doAesDecrypt(AesUtils.java:122)
        at com.teradata.data.business.DataProcessService.getDecryptData(DataProcessService.java:150)
        at com.teradata.data.business.DataProcessService.process(DataProcessService.java:92)
        at com.teradata.data.business.DataProcessService.processIdCard(DataProcessService.java:65)
        at com.teradata.data.controller.DataController.idCard(DataController.java:35)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)

发生原因

  • jdk sercurity 使用的jar包 local_policy.jar 和 US_export_policy.jar 中有对技术出口的限制,加密只有128bit,而没有限制的则有256bit

解决办法

  • 确认jdk版本以替换正确的版本,比如 1.8
[root@u-22111-iot ~]# java -version
java version "1.8.0_77"
  • 针对 jdk 1.8 版本,执行下面的脚本,替换掉这2个受限制的jar包,记得重启Java应用以生效
cd /opt/
wget -c http://iso.sqlfans.cn/jdk/jce_policy-8.zip
unzip jce_policy-8.zip
mv $JAVA_HOME/jre/lib/security/local_policy.jar $JAVA_HOME/jre/lib/security/local_policy.jar.$(date +%Y%m%d%H%M%S)
mv $JAVA_HOME/jre/lib/security/US_export_policy.jar $JAVA_HOME/jre/lib/security/US_export_policy.jar.$(date +%Y%m%d%H%M%S)
mv UnlimitedJCEPolicyJDK8/local_policy.jar $JAVA_HOME/jre/lib/security/
mv UnlimitedJCEPolicyJDK8/US_export_policy.jar $JAVA_HOME/jre/lib/security/
Copyright © www.sqlfans.cn 2024 All Right Reserved更新时间: 2022-10-13 23:08:37

results matching ""

    No results matching ""