AES 256-bit key
843811Aug 3 2006 — edited Aug 3 2006Hello. I'm just starting to learn about doing encryption with Java. I hope someone can help. Thanks.
I'm having trouble getting AES encryption to work with a 256-bit key. I HAVE downloaded and installed the unlimited strength jurisdiction policy files. Here is a small program that illustrates the problem:
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class problem
{
public static void main(String[] args) throws Exception
{
byte[] key256 =
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32};
byte[] iv = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
IvParameterSpec ivParamSpec = new IvParameterSpec(iv);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
SecretKeySpec keySpec = new SecretKeySpec(key256, "AES");
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivParamSpec);
}
}
When I run it, I get the following output:
Exception in thread "main" java.lang.SecurityException: Unsupported keysize or algorithm parameters
at javax.crypto.Cipher.init(DashoA6275)
at problem.main(problem.java:18)
ENCRYPT_MODE gives me the same problem. Also if I don't use the ivParamSpec I still get the same problem.
Can anybody tell me what I'm doing wrong? Thank you.