本文介绍了带有Bouncy Castle的AES 256bit加密:还需要无限力量政策?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用AES 256bit加密与,我想知道仍然需要BC,因为我收到一个 java.security.InvalidKeyException:以下代码的非法密钥大小
异常:
I want to use AES 256bit encryption with Bouncy Castle and I'm wondering if the "Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files" are still required despite BC because I'm receiving a java.security.InvalidKeyException: Illegal key size
exception for the following code:
public class AES256 {
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
final KeyGenerator keyGen = KeyGenerator.getInstance("AES");
keyGen.init(256); // doesn't work for 192, too
final byte[] encoded = keyGen.generateKey().getEncoded();
final SecretKeySpec keySpec = new SecretKeySpec(encoded, "AES");
final Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC");
// Please ignore static IV for this example
final IvParameterSpec iv = new IvParameterSpec(new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15});
c.init(Cipher.ENCRYPT_MODE, keySpec, iv); // throws java.security.InvalidKeyException: Illegal key size
}
}
我失踪了什么?有没有一个方法可以使用256位密钥,而没有无限力量策略文件?
What am I missing? Is there a way to use 256bit keys without the Unlimited Strength Policy files?
推荐答案
bouncycastle中的第一个问题。
First question in the bouncycastle FAQ.
这篇关于带有Bouncy Castle的AES 256bit加密:还需要无限力量政策?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!