I'm using the following code to perform encryption using mcrypt
<?PHP
define('SECURE_KEY','Somekey');
function encrypt($value){
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
return mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SECURE_KEY, $value, MCRYPT_MODE_ECB, $iv);
}
function decrypt($value){
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, SECURE_KEY, $value, MCRYPT_MODE_ECB, $iv));
}
$temp=encrypt("teststring");
printf($temp);
?>
The newer versions of php depreciates mcrypt,im looking for a replacement for the same that works with the same key and produces the same result,so that i dont need to change client side code.
I'm the author of the RFC to deprecate then remove mcrypt from PHP.
What you should absolutely do is migrate your data to use the new Sodium extension instead. Learn how to get started with libsodium in PHP. The code examples are safe to use.
If you need a "transition" step between PHP 7.1 and older, and PHP 7.2 and newer, mcrypt_compat is a polyfill library created by the phpseclib developers to facilitate migrations between mcrypt and non-abandonware libraries (OpenSSL, Sodium).
Only use it for migrations. Don't rely on it to "just work" and be secure.