How to replace mcrypt with php: 1. Open the corresponding php file; 2. Find the original encryption and decryption code; 3. Use the "openssl_encrypt" and "openssl_decrypt" methods to replace it.
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.
php How to replace mcrypt?
Mcrypt encryption and decryption alternative in php7.4
Problem description
The mcrypt_encrypt and mcrypt_decrypt functions have been abandoned since PHP 7.1.0. The original project (php5. 6) The mcrypt_encrypt and mcrypt_decrypt functions used in php7.1 and later environments will prompt that the function cannot be found, and you need to use openssl_encrypt and openssl_decrypt instead.
Solution
********************Encryption*************** ********
Copy after login
************************Decryption************ ************
Copy after login
/** * 原解密方法 * @param $str * @param string $key * @return string */ function des_decrypt($str, $key='uK9pFn56') { $str = mcrypt_decrypt(MCRYPT_DES, $key, base64_decode($str), MCRYPT_MODE_ECB); $len = strlen($str); $block = mcrypt_get_block_size('des', 'ecb'); $pad = ord($str[$len - 1]); return substr($str, 0, $len - $pad); } var_dump(des_decrypt("BKG4i231OB0=")); //解密结果:123123
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to replace mcrypt in php. For more information, please follow other related articles on the PHP Chinese website!