title: DESede (3DES) Encryption in RAILO CFML
body: <p>I've been trying for many days to try and solve this issue.</p>
  
  <p>A 3rd Party webservice requires me to send encrypted data using 3DES with ECB
  and PKCS7padding - They're using .NET</p>
  
  <p>The encrypt function within railo CFML is limited to DESede without any further options (i.e. defaults are used for cipher mode and padding). </p>
  
  <p>Has anyone had this issue in Railo and come up with a solution (java based perhaps)? - I'm seriously pulling my hair out here!</p>
  
  <p>Based on Leigh's suggestions below I made some changes:</p>
  
  <p>I've made a bit of progress, I think this key has some kind of MD5 hashing on it.</p>
  
  <p>I fished around the web and modified your solution a bit - I don't think the padding is necessary but the resultant encrypted string at first appears to be what I should expect but then closer on inspection it's incorrect:</p>
  
  <pre><code>IvParameterSpec = createObject("java", "javax.crypto.spec.IvParameterSpec");
  Cipher = createObject("java", "javax.crypto.Cipher");
  SecretKeySpec = createObject("java", "javax.crypto.spec.SecretKeySpec");
  BASE64Decoder = createObject("java", "sun.misc.BASE64Decoder");
  Str = createObject("java", "java.lang.String");
  MessageDigest = createObject("java", "java.security.MessageDigest");
  
  input  = "&lt;xml&gt;&lt;PanNumber&gt;6280390027626871&lt;/PanNumber&gt;&lt;Req_Currency_Code&gt;826&lt;/Req_Currency_Code&gt;&lt;Card_Pin&gt;1234&lt;/Card_Pin&gt;&lt;Till_Amount&gt;&lt;/Till_Amount&gt;&lt;Auth_Code&gt;&lt;/Auth_Code&gt;&lt;/xml&gt;";
  key = "06098140901984F95E139F29B479D952CB6545C177D21456";
  
  md = MessageDigest.getInstance("MD5");
  md.update(key.getBytes("UTF-8"), 0, key.length());
  keyBytes = md.digest();
  newKey = tobase64(keyBytes);
  keyBytes2  = binaryDecode(newKey, "base64");
  keyBytes2  = arrayMerge(keyBytes, arraySlice(keyBytes, 1, 8));
  allnewKey = binaryEncode(javacast("byte[]", keyBytes2), "base64");
  
  encrypted = encrypt(input, allnewKey, "desede", "base64");
  WriteDump("encrypted (CF): "&amp; encrypted);`
  </code></pre>
  
  <p>The result is: <strong>26sfwv2DHDj7EHYd5Qao8veDtPbKIcv8rDVhbLPDEaWHO27EUGRF6KrdbXe7NBUVADYMdGuagfO4Tev584dUcgKGJ2h6kWPZxooNUGMgL2xB7e00YOkLosA8wFD569sZUd1MGKuF9yCjY1zCsAE4SgohkcuK9YZ7BizQma99/W9yOsIjAfHtAqGiep4tMTQ+eFASYtPybccsgi8H4brIB/HAu0kaDSAw</strong></p>
  
  <p>The expected result is:
  <strong>26sfwv2DHDj7EHYd5Qao8veDtPbKIcv8rDVhbLPDEaWHO27EUGRF6MxaAzUpJDqQBq8NGgdqmtn6q/wVQNHGWrOE8+aetKVC78nszS3ZO8AHjwoT1igv4lGl78n8jCHHU+KwnBT7KfXIYMTCuwO/MohIiFbGyhMXPsvv3/G4OY1C2nEkN0LweLh4mTgtU8syT1M9XdmvwhaltsmPoFtoE9FujvQpJCY3</strong></p>