title: Encryption in JavaScript and decryption with PHP
body: <p>I'm encrypting my user password in JavaScript like this:</p>
  
  <pre><code> var encryptedPassword = CryptoJS.AES.encrypt(password, "Secret Passphrase");
  </code></pre>
  
  <p>It works fine but now I'm trying to decrypt in PHP on the server side like this: </p>
  
  <pre><code> $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND);
   $decryptPassword = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, "Secret Passphrase", base64_decode($password), MCRYPT_MODE_CBC, $iv);
  </code></pre>
  
  <p>it doesn't works at all, the decrypted password string looks very strange:</p>
  
  <pre><code> string(64) "&gt;�OX2MS��댗v�&lt;$�ʕ��i�̄��_��P���\�կ=�_6(�m����,4WT7��a"
  </code></pre>
  
  <p>Here is the current state of my code in JavaScript after the helpful comments:</p>
  
  <pre><code>    var encryptedPassword = CryptoJS.AES.encrypt(password, "Secret Passphrase");
      var ivHex = encryptedPassword.iv.toString();
      var ivSize = encryptedPassword.algorithm.ivSize; // same as blockSize
      var keySize = encryptedPassword.algorithm.keySize;
      var keyHex = encryptedPassword.key.toString();
      var saltHex = encryptedPassword.salt.toString(); // must be sent
      var openSslFormattedCipherTextString = encryptedPassword.toString(); // not used
      var cipherTextHex = encryptedPassword.ciphertext.toString(); // must be sent
  </code></pre>
  
  <p>I am sending saltHex and CipherTextHex to the PHP server and I'm using mcrypt_decrypt() like this:</p>
  
  <pre><code> $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), $saltHex);
   $decryptPassword = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, "Secret Passphrase", base64_decode($cipherTextHex), MCRYPT_MODE_CBC, $iv);
  </code></pre>
  
  <p>It still does't work with this updated code.</p>
  
  <p>Can someone help me to decrypt properly with mcrypt_decrypt() PHP function for a simple AES encryption method ? I'm sure I am doing something wrong with the cipher, mcrypt mode and the IV parameters inside my mcrypt_decrypt() method. Thanks if you know.</p>