Solution when illegal key size or default parameters occurs when AES is used

Source: Internet
Author: User



This error occurs when we set the key to be greater than 128 (that is, 192 or 256): illegal key size or default parameters this is because Java defaults cannot handle such a long key.

Java almost all kinds of common encryption algorithms can find the corresponding implementation. Because of the U.S. export restrictions, sun through the permissions file (Local_policy.jar, Us_export_policy.jar) to make the corresponding restrictions. So there are some problems:
The key length can not meet the requirements (such as: Java.security.InvalidKeyException:Illegal key size or default parameters);
Some algorithms are not supported, such as MD4, SHA-224 and so on.
APIs are not very convenient to use, and some common conversion aids are not available, such as Base64 encoding conversion, hexadecimal transcoding, and other tools.

Oracle provides a policy-free file on its official web site (unlimited strength Jurisdiction Policy files), and we can solve the limitation problem by simply deploying it in the JRE environment.

There is only one directory in the downloaded package, which is the JCE directory. The directory contains 4 files: README.txt, copyright.html, Local_policy.jar, and Us_export_policy.jar. The two jar files included are the files used in this configuration.
We can view the above README.txt file and you need to configure both of these jar files in the JDK's JRE environment, or in the JRE environment.
Switch to the%jdk_home%\jre\lib\security directory, covering Local_policy.jar and Us_export_policy.jar two files. Also, you may need to overwrite these two files in the%jre_home%\lib\security directory.
The ultimate goal of configuring a rights file is to enable the application to gain appropriate permissions in the running environment, and to enhance the security of the application. Typically, we install the JRE on the application server, not the JDK. Therefore, it is necessary to overwrite these two rights files in the%jre_home%\lib\security directory of the application server. Many developers tend to overlook this, leading to an accident.

To replace the paths of the Local_policy.jar and Us_export_policy.jar two files:

D:\Java\jre7\lib\security

D:\Java\jdk1.7.0_25\jre\lib\security

Where: D:\Java\jdk1.7.0_25 installation path for JDK

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.