title: How can I encrypt a string in Java to be the exact same as it is encrypted in ColdFusion?
body: <p>I have data encrypted in ColdFusion that I need to be able to decrypt and encrypt to the same exact value using Java.  I was hoping someone may be able to help me with this.  I will specify everything used in ColdFusion except for the actual PasswordKey, which I must keep secret for security purposes.  The PasswordKey is 23 characters long.  It uses upper and lowercase letters, numbers, and the + and = signs.  I know this is a lot to ask, but any help would be greatly appreciated.</p>
  
  <p>I tried using a Java encryption example I found <a href="http://www.digizol.com/2009/10/java-encrypt-decrypt-jce-salt.html" rel="nofollow">online</a> and just replacing the line below with the 23 characters used in our CF app:</p>
  
  <pre><code>private static final byte[] keyValue = new byte[] {'T', 'h', 'i', 's', 'I', 's', 'A', 'S', 'e', 'c', 'r', 'e', 't', 'K', 'e', 'y' };` 
  </code></pre>
  
  <p>But I get the error: </p>
  
  <pre><code>java.security.InvalidKeyException: Invalid AES key length: 23 bytes
  </code></pre>
  
  <p>The CF code is:</p>
  
  <pre><code>Application.PasswordKey = "***********************";
  Application.Algorithm = "AES";
  Application.Encoding = "hex";
  
  &lt;cffunction name="encryptValue" access="public" returntype="string"&gt;
          &lt;cfargument name="strEncryptThis" required="yes"&gt;
  
          &lt;cfreturn Encrypt(TRIM(strEncryptThis), Application.PasswordKey, Application.Algorithm, Application.Encoding)&gt;
  &lt;/cffunction&gt;
  
  
  &lt;cffunction name="decryptValue" access="public" returntype="string"&gt;
      &lt;cfargument name="strDecryptThis" required="yes"&gt;
  
      &lt;cfreturn Decrypt(TRIM(strDecryptThis), Application.PasswordKey, Application.Algorithm, Application.Encoding)&gt;
  &lt;/cffunction&gt;
  </code></pre>