时间:2021-07-01 10:21:17 帮助过:10人阅读
$td = mcrypt_module_open(MCRYPT_DES,'','ecb',''); //使用MCRYPT_DES算法,ecb模式
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
$ks = mcrypt_enc_get_key_size($td);
$key = "ery secret key";//密钥
$key = substr(md5($key), 0, $ks);
mcrypt_generic_init($td, $key, $iv); //初始处理
//加密
$encrypted = mcrypt_generic($td, 'This is very important data');
//结束处理
mcrypt_generic_deinit($td);
//初始解密处理
mcrypt_generic_init($td, $key, $iv);
//解密
$decrypted = mdecrypt_generic($td, $encrypted);
//结束
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
//解密后,可能会有后续的,需去掉
echo trim($decrypted) . "n";
http://www.bkjia.com/PHPjc/629707.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/629707.htmlTechArticlePHP中的 Mcrypt 可逆加密算法 ?php教程 $td = mcrypt_module_open(MCRYPT_DES,'','ecb',''); //使用MCRYPT_DES算法,ecb模式 $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($t...