title: Recreating MCRYPT_RIJNDAEL_128 in node.js
body: <p>Trying to recreate the following php encryption code in node.js:</p>
  
  <pre><code>$size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
  $iv = mcrypt_create_iv($size, MCRYPT_RAND);
  $msg = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, 'MY_KEY_LONG_STRING', 'PLAINTEXT', MCRYPT_MODE_ECB, $iv));
  </code></pre>
  
  <p>Tried this:</p>
  
  <pre><code>var text = 'PLAINTEXT';
  var len = text.length;
  for (var i = 0; i &lt; 16 - len % 16; i++) {  // pad to multiple of block size 
      text += '\0';
  }
  var key = 'MY_KEY_LONG_STRING';
  key = key.substr(0, 16); // trim to expected key size for aes128
  
  var cipher = crypto.createCipher('aes-128-ecb', key);
  cipher.setAutoPadding(false); // did our own padding, to match mcrypt_encrypt
  var encrypted = cipher.update(text, 'utf8', 'base64');
  encrypted += cipher.final('base64');
  </code></pre>
  
  <p>Getting different result from the php one...</p>
  
  <p>Also tried creating cipher with IV (which shouldn't even be used in aes-128-ecb):</p>
  
  <pre><code>var cipher = crypto.createCipheriv('aes-128-ecb', key, '');
  </code></pre>
  
  <p>Also, different result from php. Any ideas how to make this behave exactly like the php version?</p>