java aes 256 java.security.InvalidKeyException: Illegal key size after installation the policy
aes, encryption, java, sha256
Solution
Policy files should resolve the issue. Check the path environment variable to confirm that you are using the same jre which has policy files.
Problem
i have a problem with the encrypt of the bytes with an AES 256 key. I already installed the policy. Here's what I've done: - download the file: http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html - I moved the files local_policy and US_export_policy to the directory /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/security - i restart the mac But still I get an error message with the following code: ``` KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); keyGenerator.init(256); SecretKey secretKey = keyGenerator.generateKey(); Cipher decryption = Cipher.getInstance("AES/CBC/PKCS5PADDING"); decryption.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(secretKey.getEncoded())); // <-- Illegal key size ``` My Java version: ``` java version "1.7.0_40" Java(TM) SE Runtime Environment (build 1.7.0_40-b43) Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode) ``` What i have to do, to use the 256 AES encryption?