I've updated my existing system to PHP 7.4 and mcrypt has been removed and I'm looking for an alternative.
It's recommended to change the code using openssl, but I didn't see any articles posted in my case.
It is recommended to rewrite mcrypt_create_iv
for random_bytes
and mcrypt_ecb
for mcrypt_encrypt
, but there is no alternative to E and I can't think of that rewrite.
Do you have an idea?
Service.php
/**
* 3DES encryption
*
* @param string $plain Plaintext
* @return string cipher Ciphertext
*/
public function encrypt3DES($plain) {
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_3DES, MCRYPT_MODE_ECB), MCRYPT_RAND);
$cipher = bin2hex(mcrypt_ecb (MCRYPT_3DES, self::AUTH_KEY, $plain, MCRYPT_ENCRYPT, $iv));
return $cipher;
}
/**
* 3DES decryption
*
* @param string $cipher Ciphertext
* @return string Plaintext
*/
public function decrypt3DES($cipher) {
if (!ctype_xdigit($cipher)) {
return '';
}
$iv = mcrypt_create_iv (mcrypt_get_iv_size (MCRYPT_3DES, MCRYPT_MODE_ECB), MCRYPT_RAND);
$plain = mcrypt_ecb(MCRYPT_3DES, self::AUTH_KEY, pack("H*", $cipher), MCRYPT_DECRYPT, $iv);
return trim($plain);
}