<?php $key = "miyao";//密钥 $string="jiami";//需要加密的字符 $d = new d(); //加密 $crypttext = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key)))); $encrypted =trim($d->safe_b64encode($crypttext));//对特殊字符进行处理 echo $encrypted; // 解密 $key="miyao"; $crypttexttb=$d->safe_b64decode($encrypted);//对特殊字符解析 $decryptedtb = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($crypttexttb), MCRYPT_MODE_CBC, md5(md5($key))), "\0");//解密函数 echo $decryptedtb; //处理特殊字符 class d{ public function safe_b64encode($string) { $data = base64_encode($string); $data = str_replace(array('+','/','='),array('-','_',''),$data); return $data; } //解析特殊字符 public function safe_b64decode($string) { $data = str_replace(array('-','_'),array('+','/'),$string); $mod4 = strlen($data) % 4; if ($mod4) { $data .= substr('====', $mod4); } return base64_decode($data); } public function s(){ echo 1; } } ?>