具有时效性的php加密解密函数代码

前端之家收集整理的这篇文章主要介绍了具有时效性的php加密解密函数代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

代码如下:
403_3@PHP@H_403_3@function encode_pass($tex,$key,$type="encode",$expiry=0){@H_403_3@ $chrArr=array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',@H_403_3@ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',@H_403_3@ '0','1','2','3','4','5','6','7','8','9');@H_403_3@ if($type=="decode"){@H_403_3@ if(strlen($tex)<14)return false;@H_403_3@ $verity_str=substr($tex,8);@H_403_3@ $tex=substr($tex,8);@H_403_3@ if($verity_str!=substr(md5($tex),8)){@H_403_3@ //完整性验证失败@H_403_3@ return false;@H_403_3@ } @H_403_3@ }@H_403_3@ $key_b=$type=="decode"?substr($tex,6):$chrArr[rand()%62].$chrArr[rand()%62].$chrArr[rand()%62].$chrArr[rand()%62].$chrArr[rand()%62].$chrArr[rand()%62]; $rand_key=$key_b.$key; @H_403_3@ //设置时间选项@H_403_3@ $modnum=0;$modCount=0;$modCountStr="";@H_403_3@ if($expiry>0){@H_403_3@ if($type=="decode"){@H_403_3@ $modCountStr=substr($tex,6,1);@H_403_3@ $modCount=$modCountStr=="a"?10:floor($modCountStr);@H_403_3@ $modnum=substr($tex,7,$modCount);@H_403_3@ $rand_key=$rand_key.(floor((time()-$modnum)/$expiry));@H_403_3@ }else{@H_403_3@ $modnum=time()%$expiry;@H_403_3@ $modCount=strlen($modnum);@H_403_3@ $modCountStr=$modCount==10?"a":$modCount; $rand_key=$rand_key.(floor(time()/$expiry)); @H_403_3@ }@H_403_3@ $tex=$type=="decode"?base64_decode(substr($tex,(7+$modCount))):"xugui".$tex;@H_403_3@ }else{@H_403_3@ $tex=$type=="decode"?base64_decode(substr($tex,6)):"xugui".$tex;@H_403_3@ }@H_403_3@ $rand_key=md5($rand_key);

@H_403_3@ $texlen=strlen($tex);@H_403_3@ $reslutstr="";@H_403_3@ for($i=0;$i<$texlen;$i++){@H_403_3@ $reslutstr.=$tex{$i}^$rand_key{$i%32};@H_403_3@ }@H_403_3@ if($type!="decode"){@H_403_3@ $reslutstr=trim(base64_encode($reslutstr),"==");@H_403_3@ $reslutstr=$modCount?$modCountStr.$modnum.$reslutstr:$reslutstr;@H_403_3@ $reslutstr=$key_b.$reslutstr;@H_403_3@ $reslutstr=substr(md5($reslutstr),8).$reslutstr;@H_403_3@ }else{@H_403_3@ if(substr($reslutstr,5)!="xugui"){@H_403_3@ return false;@H_403_3@ }@H_403_3@ $reslutstr=substr($reslutstr,5);@H_403_3@ }@H_403_3@ return $reslutstr;@H_403_3@}@H_403_3@$psa=encode_pass("woshi ceshi yong de ","taintainxousad","encode",120);@H_403_3@echo $psa;@H_403_3@echo "\r\n解密:";@H_403_3@echo encode_pass($psa,'decode',120);@H_403_3@?>@H_403_3@

函数具有时效性,只要过期就不能解密!通过时间动态加密 加密后数据多样化,增加破解难度

猜你在找的PHP相关文章