Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP7.1 mcrypt alternative

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?

like image 572
Tibi Avatar asked Jan 19 '17 11:01

Tibi


2 Answers

You should use openssl_encrypt instead.

like image 169
Aleksa Arsić Avatar answered Oct 16 '22 20:10

Aleksa Arsić


Consider using defuse or RNCryptor, they provide a complete solution, are being maintained and is correct.

like image 1
zaph Avatar answered Oct 16 '22 21:10

zaph