/** * Decrypt the ciphertext. * * @param cipherText The ciphertext to decrypt * @return decrypted plaintext */ Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); SecretKeySpec key_spec = new SecretKeySpec(aesKey, "AES"); IvParameterSpec iv = new IvParameterSpec(Arrays.copyOfRange(aesKey, 0, 16)); cipher.init(Cipher.DECRYPT_MODE, key_spec, iv); // Decode the ciphertext using BASE64 byte[] encrypted = Base64.decodeBase64(cipherText); // decrypt original = cipher.doFinal(encrypted); The following is omitted. . . . . Please leave me a message if needed
When using JAVA to process the received message of WeChat, when processing the ciphertext, if you encounter
java.security.InvalidKeyException: Illegal key size or default parameters
this exception. Then you need to add the unpolished permission file to your JDK or JRE environment.
The download address is as follows:
● Java 5.0 No Policy Restriction File
● Java 6 No Policy Restriction File
● Java 7 No Policy Restriction File
● Java 8 no policy restriction file
● Other versions have no policy restriction file
There is only one directory in the downloaded compressed package, which is the jce directory. This 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. You need to configure the above two jar files in the JRE environment of the JDK, or in the JRE environment.
Switch to the %JDK_Home%\jre\lib\security directory and overwrite the local_policy.jar and US_export_policy.jar files accordingly. At the same time, you may need to overwrite these two files in the %JRE_Home%\lib\security directory.
The ultimate purpose of configuring the permissions file is to enable the application to obtain the corresponding permissions in the running environment, which can enhance the security of the application. Usually, we install the JRE on the application server, not the JDK. Therefore, it is necessary to overwrite these two permission files in the %JRE_Home%\lib\security directory of the application server. Many developers tend to ignore this, leading to accidents.