title: Javascript DES encryption/PHP decryption
body: <p>I have a PHP endpoint that is used by several websites. While POSTing data to the endpoint the sites use encrypted headers to identify various information. The sites use the standard PHP <code>mcrypt_ecb</code> function, and the endpoint decrypts the variables like this:</p>
  
  <pre><code>$var = trim(mcrypt_ecb(MCRYPT_DES, $key, base64_decode($input), MCRYPT_DECRYPT)));
  </code></pre>
  
  <p>I don't really have much chance of altering the PHP endpoint, although I could conceivably make another endpoint if <code>mcrypt_ecb</code> doesn't play nicely. </p>
  
  <p>I now have a PhoneGap app, which also needs to send the encrypted headers. Phonegap can only really use javascript to POST to a remote server. I've looked at the Google <a href="https://code.google.com/p/crypto-js/" rel="nofollow noreferrer">CryptoJS</a> to try to acheive this, along side a base64 library. Note that the key is the same as the $key var above. </p>
  
  <pre><code>var encrypted = CryptoJS.DES.encrypt(user.email, key).toString();
  var base64 = base64.encode(encrypted);
  </code></pre>
  
  <p>The problem is that the encrypted string (and I have tried without the base64 encode/decode) when passed through <code>mcrypt_ecb</code> is garbage. Apparently there are different methods of triple DES encryption? </p>
  
  <p>How would I create a <code>mcrypt_ecb</code> compatible encrypted string in JavaScript?</p>