【发布时间】:2014-08-15 03:05:52
【问题描述】:
我已将 JCE Unlimited strength 安装到 JAVA_HOME\lib\security
但是,Cipher.getMaxAllowedKeyLength("AES") 我仍然得到 128。
我想知道我是否在错误的位置安装了 JCE。
我在 2 个地方安装了 Java。
- C:\Program Files\Java\jre7
- C:\Development\Java\jdk1.6.0_21
谁能告诉我安装JCE Unlimited strength 的正确位置在哪里? 非常感谢您的帮助。
我的代码:
KeyGenerator generator = KeyGenerator.getInstance("AES");
generator.init(256); SecretKey secretKey = generator.generateKey();
byte[] raw= secretKey.getEncoded();
SecretKeySpec sskey= new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
if (mode == Cipher.ENCRYPT_MODE) {
Cipher.getMaxAllowedKeyLength("AES"));
cipher.init(Cipher.ENCRYPT_MODE, sskey);
CipherInputStream cis = new CipherInputStream(is, cipher);
doCopy(cis, os);
} else if (mode == Cipher.DECRYPT_MODE) {
cipher.init(Cipher.DECRYPT_MODE, sskey);
CipherOutputStream cos = new CipherOutputStream(os, cipher);
doCopy(is, cos);
}
【问题讨论】:
-
你能显示你使用的代码吗?它应该只取决于您使用的密钥的长度。
-
更新了我的代码。谢谢。
标签: java encryption cryptography jce