java.security.InvalidKeyException: Illegal key size or default parameters in android
private String cryptKey = "qkjll5@2md3gs5Q@FDFqf";
By default Java supports only 128-bit encryption
128bits == 16Bytes == 16 Chars.
So cryptKey
cannot exceed 16 characters.
If you want to exceed more than 16 character you have to install Java Cryptography Extension (JCE) Unlimited Strength.
Why 128bits?
There have been updates since Java 8/9
- The Unlimited Strength Jurisdiction Policy Files are included with Java 9 and used by default
- Starting with Java 8 Update 161, Java 8 defaults to the Unlimited Strength Jurisdiction Policy.
Starting with Java 8 Update 151, the Unlimited Strength Jurisdiction Policy is included with Java 8 but not used by default. To enable it, you need to edit the java.security file in
<java_home>/jre/lib/security
(for JDK) or<java_home>/lib/security
(for JRE). Uncomment (or include) the linecrypto.policy=unlimited
Make sure you edit the file using an editor run as administrator. The policy change only takes effect after restarting the JVM
Before Java 8 Update 151 you have to download JCE Unlimited Strength Jurisdiction Policy files and replace.
For more details see How to install Java Cryptography Extension (JCE) unlimited strength jurisdiction policy files
PS: Above link goes to my personal blog that has additional details.
Default JDK supports encryption only through 128 bit keys becuase of American restrictions. So to support encryption from 256 bit long key we have to replace local_policy.jar and US_export_policy.jars in $JAVA_HOME/java-8-oracle/jre/lib/security folder otherwise it will give java.security.InvalidKeyException: Illegal key size or default