title: How to use PBEWITHHMACSHA256ANDAES_256 algorithm from JCE
body: <p>I'd like to use the <code>PBEWITHHMACSHA256ANDAES_256</code> algorithm from the <a href="http://docs.oracle.com/javase/8/docs/technotes/guides/security/SunProviders.html#SunJCEProvider" rel="nofollow noreferrer">SunJCE provider</a> in Java8. </p>
  
  <p>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 <code>PBEWITHHMACSHA256ANDAES_256</code> algorithm.</p>
  
  <p>I have these two jars:</p>
  
  <pre><code>jdk1.8.0_40\jre\lib\jce.jar
  jdk1.8.0_40\jre\lib\ext\sunjce_provider.jar
  </code></pre>
  
  <p>There's this entry in <code>jdk1.8.0_40\jre\lib\security\java.security</code></p>
  
  <pre><code>security.provider.5=com.sun.crypto.provider.SunJCE
  </code></pre>
  
  <p>There's this entry in <code>jdk1.8.0_40\jre\lib\security\java.policy</code></p>
  
  <pre><code>grant codeBase "file:${{java.ext.dirs}}/*" {
      permission java.security.AllPermission;
  };
  </code></pre>
  
  <p>I can see <code>com.sun.crypto.provider.SunJCE</code> in the array when I call <code>Security.getProviders()</code></p>
  
  <p>But the following code throws <code>EncryptionOperationNotPossibleException</code></p>
  
  <pre><code>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);
      }
  }
  </code></pre>
  
  <p>Exception</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Any ideas why PBEWITHHMACSHA256ANDAES_256 is throwing EncryptionOperationNotPossibleException?</p>