KeyGenerator keyGen = KeyGenerator.getInstance("AES");
keyGen.init(256);
Key key = keyGen.generateKey();
but the exception happens when running java AesExample.
The reason is the import regulation in some countries. AES is limited to 128 bits in default security policy.
Algorithm | Maximum Keysize |
---|---|
DES | 64 |
DESede | * |
RC2 | 128 |
RC4 | 128 |
RC5 | 128 |
RSA | * |
all others | 128 |
We can change the security policy by downloading the zip from the site.
Please select "Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files for JDK/JRE 8" to download the zip file, jce_policy-8.zip, if we use JDK 8.
Decompress the ZIP file to get the both jar files.
local_policy.jar
US_export_policy.jar
Copy them to the directory to replace old files.
JAVA_HOME\jre\lib\security
Now we can use AES-256 in Java environment.
>javac AesExample.java
>java AesExample
-Count
No comments:
Post a Comment