java aes 256 java.security.InvalidKeyException:安装策略后的非法密钥大小 [英] java aes 256 java.security.InvalidKeyException: Illegal key size after installation the policy

查看:115
本文介绍了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.getInstance(AES / CBC / PKCS5PADDING);
decrypt.init(Cipher.DECRYPT_MODE,secretKey,
new IvParameterSpec(secretKey.getEncoded())); //< - 非法密钥大小

我的Java版本:

  java版本1.7.0_40
Java(TM)SE运行时环境(build 1.7.0_40-b43)
Java HotSpot )64位服务器虚拟机(构建24.0-b56,混合模式)

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

解决方案

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


i have a problem with the encrypt of the bytes with an AES 256 key. I already installed the policy. Here's what I've done:

  1. download the file: http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html
  2. I moved the files local_policy and US_export_policy to the directory /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/security
  3. i restart the mac

But still I get an error message with the following code:

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

My Java version:

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)

What i have to do, to use the 256 AES encryption?

解决方案

Policy files should resolve the issue. Check the path environment variable to confirm that you are using the same jre which has policy files.

这篇关于java aes 256 java.security.InvalidKeyException:安装策略后的非法密钥大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆