代码演示如下:

方法一

<"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); 

?>
标签:
php加密,php解密

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com

评论“六种php加密解密方法实例讲解”

暂无“六种php加密解密方法实例讲解”评论...

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。