🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
> php7.*以下不支持 ~~~ $key="zhelishi key"; class Mcrypt { /** * 获取key */ private static function getKey(){ global $key; return md5($key); } /** * 加密方法 */ public static function encrypt($value){ $td = mcrypt_module_open('tripledes','','ecb',''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),MCRYPT_DEV_RANDOM); $key = substr(self::getKey(),0,mcrypt_enc_get_key_size($td)); mcrypt_generic_init($td,$key,$iv); $ret = base64_encode(mcrypt_generic($td,$value)); mcrypt_generic_deinit($td); mcrypt_module_close($td); return $ret; } /** * 解密方法 */ public static function dencrypt($value){ $td = mcrypt_module_open('tripledes','','ecb',''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),MCRYPT_DEV_RANDOM); $key = substr(self::getKey(), 0, mcrypt_enc_get_key_size($td)); mcrypt_generic_init($td, $key, $iv); $ret = trim(mdecrypt_generic($td, base64_decode($value))) ; mcrypt_generic_deinit($td); mcrypt_module_close($td); return $ret; } } $str = "dddddddddddddddddddddddd"; $sec = base64_encode(Mcrypt::encrypt($str)); var_dump($sec); $jiemi = Mcrypt::dencrypt(base64_decode($sec)); var_dump($jiemi); ~~~