在oarcle jdk1.8上执行256位的aes秘钥加密报错如下:

java.lang.RuntimeException: java.security.InvalidKeyException: Illegal key size

at com.xx.opal.core.utils.aes.AESTool.encryptWithoutEncode(AESTool.java:33)

at com.xx.opal.aes.AESTest.test(AESTest.java:19)

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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

at org.junit.runner.JUnitCore.run(JUnitCore.java:137)

at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)

at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)

at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)

at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

解决方法:

方式1:添加无限制配置

策略文件下载地址(jar包)

JDK6的下载地址:

http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html

JDK7的下载地址:

http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html

JDK8的下载地址:

http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html

下载后解压,可以看到local_policy.jar和US_export_policy.jar以及readme.txt。

如果安装了JRE,将两个jar文件放到%JRE_HOME%\lib\security下覆盖原来文件,记得先备份。

如果安装了JDK,将两个jar文件也放到%JDK_HOME%\jre\lib\security下。

方式2:使用openjdk版本(1.8及以下版本)

例如:

openjdk version "1.8.0_222"

OpenJDK Runtime Environment (build 1.8.0_222-b10)

OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)

方式3:升级jdk版本

方式4:使用反射解除限制

方式5:使用bc非标准api

Bouncy Castle,三方类库通常包含JCE标准实现,通过添加第三方Provider后使用JCE任然不能解决问题

方式6:设置crypto.policy属性(1.8_u151版本之后的)

Security.setProperty("crypto.policy", "unlimited");

结论

最终采用了设置crypto.policy属性

最新文章

  1. java基础2_运算符,选择语句
  2. 文本数据源Fields Format
  3. Mac 使用笔记
  4. 【Derby 系列】Apache Derby 功能特点
  5. 如何在redhat下安装WineQQ
  6. ECMall的MySQL数据调用的简单方法
  7. 链表的基本操作(Basic Operations on a Linked List)
  8. Java基础之静态变量
  9. SDWebImage内部实现过程
  10. ubuntu phone/touch的源码从哪里下载?
  11. 作为测试人员,我是这么报BUG的
  12. jq事件
  13. HBase Master启动过程
  14. sieve的objective-c实现
  15. java并发包分析之———concurrentHashMap
  16. 使用Guava的RateLimiter完成简单的大流量限流
  17. python调用mediainfo工具批量提取视频信息
  18. java代码执行字符串中的逻辑运算方法
  19. 通过 DDNS 解决宽带拨号 ip 变化问题
  20. LabTool : LPC LINK2, LPC4370 cheap scope: 80Ms/s 12 bit

热门文章

  1. POJ 2455:Secret Milking Machine(二分+最大流)
  2. mongo创建集合
  3. 使用@Transactional注意的问题
  4. springboot自动装配(2)---实现一个自定义自动装配组件
  5. .NET CORE上传文件到码云仓库【搭建自己的图床】
  6. 【题解】【A % B Problem(P1865)】-C++
  7. koa2服务端使用jwt进行鉴权及路由权限分发
  8. Eclipse引入DTD文件
  9. MySql的数据库优化到底优啥了都??(2)
  10. 小白学python-day03-系统位数、变量、用户输入、if else