ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
> 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); ~~~