openssl_decrypt always returns false
<p>I tried to migrate my encryption from mcrypt to openssl but the decryption keeps failing. The code Below shows my encryption function. I placed the var_dump in the encryption function to verify decryption with identical variables works, which it does not. </p>

<p>I tried the following changes to the code, none worked:</p>

<ul>
<li><code>base64_decode($encrypted)</code></li>
<li>just out of curiosity <code>base64_encode($encrypted)</code></li>
<li>all these variants with options set to:0(default value),OPENSSL_RAW_DATA,OPENSSL_ZERO_PADDING</li>
</ul>

<p><b></b></p>

<pre><code>function encryptString($data){  
    $key = "1A534";

    do{
        $iv = random_bytes(100);
    }while(strpos($iv,"|Z|")!==false);

    $encrypted = openssl_encrypt($data,"aes-256-gcm",$key,false,$iv);   
    var_dump(openssl_decrypt($encrypted,"aes-256-gcm",$key,OPENSSL_RAW_DATA,$iv));
    $output = $iv . "|Z|" . $encrypted;
    $output = base64_encode($output);   
    return $output;
}
</code></pre>

<p>PHP Version is 7.0.5-1+deb.sury.org~trusty+1</p>

<p>OpenSSL Version is OpenSSL 1.0.2g 1 Mar 2016 </p>

<p>Why keeps openssl_decrypt returning false? I successfully encrypted with the same variables just the line above.</p>