java aes 256 java.security.InvalidKeyException:安装策略后出现非法密钥大小

我用AES 256密钥加密字节有问题。 我已经安装了这个政策。 这就是我所做的:

  1. 下载文件: http : //www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html
  2. 我将文件local_policy和US_export_policy移动到目录/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/security
  3. 我重启mac

但我仍然收到以下代码的错误消息:

KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); keyGenerator.init(256); SecretKey secretKey = keyGenerator.generateKey(); Cipher decryption = Cipher.getInstance("AES/CBC/PKCS5PADDING"); decryption.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(secretKey.getEncoded())); // <-- Illegal key size 

我的Java版本:

 java version "1.7.0_40" Java(TM) SE Runtime Environment (build 1.7.0_40-b43) Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode) 

我需要做什么,使用256 AES加密?

策略文件应该可以解决问题。 检查路径环境变量以确认您使用的是具有策略文件的相同jre。

重要提示:您已了解自己的位置。 例如:在我的计算中有C:\Java\jre7\lib\securityC:\Java\jdk1.7.0_02\jre\lib\security ,但是eclipse显示jre是C:\Java\jre7\lib\security ,所以你必须将两个文件复制到这里。

我从这个位置下载的策略文件http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html粘贴到位置jre/lib/security/它工作.. ..