I am attempting to perform AES encryption using Java.
I have a key size of 32 bytes represented by 64 ASCII characters. (I want to perform AES with a 32 byte key which I believe is AES 1024 bit)
byte[] key = DatatypeConverter.parseHexBinary("03d42e229a8992a195a7bc0789a0fb6636cc5edeb0f106c8ca0d843b269f5396");
When I call the below method, I receive the following:
java.security.InvalidKeyException: Illegal key size or default parameters
Here is my method in Java
public static byte[] AESDecryption(byte[] key, byte[] data)
{
byte[] retval = null;
try
{
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding", "SunJCE");
SecretKeySpec thekey = new SecretKeySpec(key,"AES");
cipher.init(Cipher.DECRYPT_MODE, thekey);
retval = cipher.doFinal(data);
}
catch (NoSuchAlgorithmException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (NoSuchProviderException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (NoSuchPaddingException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidKeyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BadPaddingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return retval;
}