时间:2021-07-01 10:21:17 帮助过:26人阅读
function encrypt($key, $plain_text) {
$plain_text = trim($plain_text);
$iv = substr(md5($key), 0,mcrypt_get_iv_size(MCRYPT_CAST_256,MCRYPT_MODE_CFB));
$c_t = mcrypt_cfb (MCRYPT_CAST_256, $key, $plain_text, MCRYPT_ENCRYPT, $iv);
return trim(chop(base64_encode($c_t)));
}
$key可以随使设个字符串,$plain_text为想要加密的字符串。与之对应的解密函数:
function decrypt($key, $c_t) {
$c_t = trim(chop(base64_decode($c_t)));
$iv = substr(md5($key), 0,mcrypt_get_iv_size (MCRYPT_CAST_256,MCRYPT_MODE_CFB));
$p_t = mcrypt_cfb (MCRYPT_CAST_256, $key, $c_t, MCRYPT_DECRYPT, $iv);
return trim(chop($p_t));
}
$plain_text为想要解密的字符串;
注意事项:如果用url将加密的字符串作为参数传递,要使用URLEncode()函数将其加密,否则用decrypt($key, $c_t)函数解密获得的参数将得不到原来的字符串。
http://www.bkjia.com/PHPjc/364698.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/364698.htmlTechArticle有时候我们不想让,一个网页地址给人看到,简单的方法就是将它加密成一串字符,函数如下: function encrypt($key, $plain_text) { $plain_text = t...