title: AES 256 on the client side (JS) and in the server (PHP)
body: <p>I'm trying to encrypt and decrypt data on the server side and the client using the same type of operation, which is AES-256.</p>
  
  <p>On the server I use PHP and client I use CryptoJS so far I could only encrypt and decrypt the client on the server, see the code:</p>
  
  <p><strong>JS</strong></p>
  
  <pre><code>&lt;script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"&gt;&lt;/script&gt;
  &lt;script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/pbkdf2.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      var salt = CryptoJS.lib.WordArray.random(128/8); 
      var key256Bits500Iterations = CryptoJS.PBKDF2("Secret Passphrase", salt, { keySize: 256/32, iterations: 500 });
      var iv  = CryptoJS.enc.Hex.parse('101112131415161718191a1b1c1d1e1f');
  
      var encrypted = CryptoJS.AES.encrypt("Message", key256Bits500Iterations, { iv: iv });  
      var data_base64 = encrypted.ciphertext.toString(CryptoJS.enc.Base64); 
      var iv_base64   = encrypted.iv.toString(CryptoJS.enc.Base64);       
      var key_base64  = encrypted.key.toString(CryptoJS.enc.Base64);
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>&lt;?php
      $encrypted = base64_decode("data_base64"); // data_base64 from JS
      $iv        = base64_decode("iv_base64");   // iv_base64 from JS
      $key       = base64_decode("key_base64");  // key_base64 from JS
  
      $plaintext = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_128, $key, $encrypted, MCRYPT_MODE_CBC, $iv ), "\t\0 " );
  </code></pre>
  
  <p>How can I encrypt and decrypt data on both sides (client and server) so that communicate in the same language using PHP and CryptoJS?</p>