代码演示如下:

方法一

<"12"); 
 return $decrypted; 
 }else{ 
 $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key)))); 
 return $encrypted; 
 } 
} 
 
//加密:"z0JAx4qMwcF+db5TNbp/xwdUM84snRsXvvpXuaCa4Bk=" 
echo encryptDecrypt('password', 'Helloweba欢迎您',0); 
//解密:"Helloweba欢迎您" 
echo encryptDecrypt('password', 'z0JAx4qMwcF+db5TNbp/xwdUM84snRsXvvpXuaCa4Bk=',1); 
"htmlcode">
<"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+"; 
 $nh = rand(0,64); 
 $ch = $chars[$nh]; 
 $mdKey = md5($key.$ch); 
 $mdKey = substr($mdKey,$nh%8, $nh%8+7); 
 $txt = base64_encode($txt); 
 $tmp = ''; 
 $i=0;$j=0;$k = 0; 
 for ($i=0; $i<strlen($txt); $i++) { 
 $k = $k == strlen($mdKey) "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+"; 
 $ch = $txt[0]; 
 $nh = strpos($chars,$ch); 
 $mdKey = md5($key.$ch); 
 $mdKey = substr($mdKey,$nh%8, $nh%8+7); 
 $txt = substr($txt,1); 
 $tmp = ''; 
 $i=0;$j=0; $k = 0; 
 for ($i=0; $i<strlen($txt); $i++) { 
 $k = $k == strlen($mdKey) "htmlcode">
<"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+"; 
 $nh = rand(0,64); 
 $ch = $chars[$nh]; 
 $mdKey = md5($key.$ch); 
 $mdKey = substr($mdKey,$nh%8, $nh%8+7); 
 $txt = base64_encode($txt); 
 $tmp = ''; 
 $i=0;$j=0;$k = 0; 
 for ($i=0; $i<strlen($txt); $i++) { 
 $k = $k == strlen($mdKey) "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+"; 
 $ch = $txt[0]; 
 $nh = strpos($chars,$ch); 
 $mdKey = md5($key.$ch); 
 $mdKey = substr($mdKey,$nh%8, $nh%8+7); 
 $txt = substr($txt,1); 
 $tmp = ''; 
 $i=0;$j=0; $k = 0; 
 for ($i=0; $i<strlen($txt); $i++) { 
 $k = $k == strlen($mdKey) "htmlcode">
<"1"; 
$key = "testkey"; 
$encrypt = passport_encrypt($txt,$key); 
$decrypt = passport_decrypt($encrypt,$key); 
 
echo $encrypt."<br>"; 
echo $decrypt."<br>"; 
 
"htmlcode">
<"htmlcode">
<?php 
//函数encrypt($string,$operation,$key)中$string:需要加密解密的字符串;$operation:判断是加密还是解密,E表示加密,D表示解密;$key:密匙。 
function encrypt($string,$operation,$key=''){ 
 $key=md5($key); 
 $key_length=strlen($key); 
 $string=$operation=='D'?base64_decode($string):substr(md5($string.$key),0,8).$string; 
 $string_length=strlen($string); 
 $rndkey=$box=array(); 
 $result=''; 
 for($i=0;$i<=255;$i++){ 
 $rndkey[$i]=ord($key[$i%$key_length]); 
 $box[$i]=$i; 
 } 
 for($j=$i=0;$i<256;$i++){ 
 $j=($j+$box[$i]+$rndkey[$i])%256; 
 $tmp=$box[$i]; 
 $box[$i]=$box[$j]; 
 $box[$j]=$tmp; 
 } 
 for($a=$j=$i=0;$i<$string_length;$i++){ 
 $a=($a+1)%256; 
 $j=($j+$box[$a])%256; 
 $tmp=$box[$a]; 
 $box[$a]=$box[$j]; 
 $box[$j]=$tmp; 
 $result.=chr(ord($string[$i])^($box[($box[$a]+$box[$j])%256])); 
 } 
 if($operation=='D'){ 
 if(substr($result,0,8)==substr(md5(substr($result,8).$key),0,8)){ 
 return substr($result,8); 
 }else{ 
 return''; 
 } 
 }else{ 
 return str_replace('=','',base64_encode($result)); 
 } 
} 
 
$str = 'abc'; 
$key = 'www.helloweba.com'; 
$token = encrypt($str, 'E', $key); 
echo '加密:'.encrypt($str, 'E', $key); 
echo '解密:'.encrypt($str, 'D', $key); 

?>
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!