title: Convert mcrypt_generic to openssl_encrypt
body: <p><code>PHP</code> no longer supports <code>mcrypt</code>. I have to make an OpenSSL alternative that has the exact same output as I only have access to half the code base. My attempts have all failed. As you can see below OS doesn't match MC. I've tried different <strong><code>$methods</code></strong> and combinations of <code>OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING</code>.</p>
  
  <p>Where am I going wrong?</p>
  
  <pre><code>const n = "\n";
  $text= 'hello my friends';
  $method = 'AES-128-CBC';
  $key = base64_decode('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA');
  $text = base64_decode('MDEyMzQ1Njc4OUFCQ0RFRgAAAAYxMjM0NTYxMjMDAwM=');
  $size = openssl_cipher_iv_length($method);
  $iv = substr($key, 0, $size);
  
  // MCRYPT METHOD
  $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
  mcrypt_generic_init($module, $key, $iv);
  $mcrypt = mcrypt_generic($module, $text);
  
  // OPENSSL METHOD
  $method = 'AES-128-CBC';
  $openssl = openssl_encrypt($text, $method, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
  
  echo "MC: " . base64_encode($mcrypt) . n;
  echo "OS: " . base64_encode($openssl) . n;
  
  /*
  MC: 9+gMhSSAHhJ4g4rdjwP02YQJTfU2qEThBco+W9ob9UU=
  OS: Qsz5HitF4X+2DV48wh7ExCjWjGEOAl88MKXk/g24Z/I=
  */
  </code></pre>