PHP7.1 mcrypt alternative

Tibi picture Tibi · Jan 19, 2017 · Viewed 42.7k times · Source

Mcrypt function has been deprecated as of PHP 7.1.0.

My deprecated string encode / decode functions:

$key: secret key
$str: string


$encoded = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $str, MCRYPT_MODE_CBC, md5(md5($key))));

$decoded = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($str), MCRYPT_MODE_CBC, md5(md5($key))), "\0");

Can you suggest some alternatives?

Answer

Aleksa Arsić picture Aleksa Arsić · Jan 19, 2017

You should use openssl_encrypt instead.