Replacing mcrypt_encrypt using MCRYPT_RIJNDAEL_256 with openssl_encrypt
<p>As you guys probably know, the extension mcrypt will be deprecated on php 7.1.</p>

<p>I use to maintain a "legacy" application that I want to migrate eventually to this version so I ran the tests and verified that I can't get 100% of coverage anymore, since there's a piece of code that use the following code:</p>

<pre class="lang-php prettyprint-override"><code>$key = 'sA*(DH';

// initialization vector
$iv = md5(md5($key));
$output = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string,     MCRYPT_MODE_CBC, $iv));
</code></pre>

<p>I tried to port this piece of code to openssl_encrypt using this code</p>

<pre class="lang-php prettyprint-override"><code>$key = md5('sA*(DH');
$iv = md5($key);
echo base64_encode(openssl_encrypt($data, "aes-256-cbc", $key, OPENSSL_RAW_DATA, $iv));
</code></pre>

<p>But I have 2 problems with this:</p>

<ol>
<li>The IV lenght should be 16 chars (and md5 gives me 32), so I get a PHP Warning</li>
<li>The output it's not the same (even if I truncate to 16 chars)</li>
</ol>

<p>Anyone had similar problems (or know how to fix it?)</p>

<p>BTW: I'm using the dev master version of PHP (supposed to be 7.1.0 alpha 3).</p>