I'd like to use the PBEWITHHMACSHA256ANDAES_256
algorithm from the SunJCE provider in Java8.
It looks like the jars and all of the config is in place out-of-the-box in Java8 but I'm not able to use the PBEWITHHMACSHA256ANDAES_256
algorithm.
I have these two jars:
jdk1.8.0_40\jre\lib\jce.jar
jdk1.8.0_40\jre\lib\ext\sunjce_provider.jar
There's this entry in jdk1.8.0_40\jre\lib\security\java.security
security.provider.5=com.sun.crypto.provider.SunJCE
There's this entry in jdk1.8.0_40\jre\lib\security\java.policy
grant codeBase "file:${{java.ext.dirs}}/*" {
permission java.security.AllPermission;
};
I can see com.sun.crypto.provider.SunJCE
in the array when I call Security.getProviders()
But the following code throws EncryptionOperationNotPossibleException
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
import org.junit.Assert;
import org.junit.Test;
public class EncryptionTest {
@Test
public void test() {
SimpleStringPBEConfig pbeConfig = new SimpleStringPBEConfig();
pbeConfig.setAlgorithm("PBEWITHHMACSHA256ANDAES_256");
pbeConfig.setPassword("changeme");
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setConfig(pbeConfig);
String encrypted = encryptor.encrypt("foo");
String decrypted = encryptor.decrypt(encrypted);
Assert.assertEquals("foo", decrypted);
}
}
Exception
org.jasypt.exceptions.EncryptionOperationNotPossibleException: Encryption raised an exception. A possible cause is you are using strong encryption algorithms and you have not installed the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files in this Java Virtual Machine
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.handleInvalidKeyException(StandardPBEByteEncryptor.java:999)
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.encrypt(StandardPBEByteEncryptor.java:868)
at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.encrypt(StandardPBEStringEncryptor.java:642)
at foo.bar.EncryptionTest.test(EncryptionTest.java:40)
Any ideas why PBEWITHHMACSHA256ANDAES_256 is throwing EncryptionOperationNotPossibleException?