AES 256位加密

问题描述:

我试图加密使用AES 256位加密,但是我不断收到错误一些数据 - 同时加密AES 256位加密

错误:java.security.InvalidKeyException:非法密钥大小或默认参数

我的代码是 -

key = "abcd123456789kjd"; 
byteKey = key.getBytes(); 
MessageDigest sha = MessageDigest.getInstance("SHA-256"); 
byteKey = sha.digest(byteKey); 
byteKey = Arrays.copyOf(byteKey, 32); // use only first 256 bit 
secretKey = new SecretKeySpec(byteKey, "AES"); 
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); 
cipher.init(Cipher.ENCRYPT_MODE, secretKey); 

有人可以帮忙弄清楚为什么错误即将到来。这是工作,如果我把它变成128位而不是256位。

默认情况下,Java只支持128位加密。如果你想超过你需要安装的无限强度文件。要做到这一点,请下载jar文件并从zip中提取jar文件并将它们保存在$ {java.home}/jre/lib/security /中。

详细请看这里:https://*.com/a/6481658/1008278

+0

是的,这是问题的感谢! – AP01