您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > 电子商务 > 怎样给PHP源代码加密PHP二进制加密与解密的解决办法
怎样给PHP源代码加密PHP二进制加密与解密的解决办法怎样给PHP源代码加密?PHP二进制加密与解密的解决办法作者:字体:[增加减小]类型:转载本篇文章小编为大家介绍,怎样给PHP源代码加密?PHP二进制加密与解密的解决办法。需要的朋友参考下分享2种PHP的源码加密方式,此加密方法支持任意PHP版。注意,加密后的PHP代码无需第三方工具解密,像往常一样,直接运行即可。复制代码代码如下:<?phpfunctionencode_file_contents($filename){$type=strtolower(substr(strrchr($filename,'.'),1));if('php'==$type&&is_file($filename)&&is_writable($filename)){//如果是PHP文件并且可写则进行压缩编码$contents=file_get_contents($filename);//判断文件是否已经被编码处理$contents=php_strip_whitespace($filename);//去除PHP头部和尾部标识$headerPos=strpos($contents,'<?php');$footerPos=strrpos($contents,'?>');$contents=substr($contents,$headerPos+5,$footerPos-$headerPos);$encode=base64_encode(gzdeflate($contents));//开始编码$encode='<?php'.\neval(gzinflate(base64_decode(.'.$encode.'.)));\n\n?>;returnfile_put_contents($filename,$encode);}returnfalse;}//调用函数$filename='dam.php';encode_file_contents($filename);echoOK,加密完成!?>加密方式2:复制代码代码如下:<?phpfunctionRandAbc($length=){//返回随机字符串$str=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz;returnstr_shuffle($str);}$filename='index.php';//要加密的文件$T_k1=RandAbc();//随机密匙1$T_k2=RandAbc();//随机密匙2$vstr=file_get_contents($filename);$v1=base64_encode($vstr);$c=strtr($v1,$T_k1,$T_k2);//根据密匙替换对应字符。$c=$T_k1.$T_k2.$c;$q1=O00O0O;$q2=O0O000;$q3=O0OO00;$q4=OO0O00;$q5=OO0000;$q6=O00OO0;$s='$'.$q6.'=urldecode(%6E1%7A%62%2F%6D%615%5C%76%740%6928%2D%70%78%75%71%79%2A6%6C%72%6B%64%679%5F%65%68%63%73%77%6F4%2B%6637%6A);$'.$q1.'=$'.$q6.'{3}.$'.$q6.'{6}.$'.$q6.'{33}.$'.$q6.'{30};$'.$q3.'=$'.$q6.'{33}.$'.$q6.'{10}.$'.$q6.'{24}.$'.$q6.'{10}.$'.$q6.'{24};$'.$q4.'=$'.$q3.'{0}.$'.$q6.'{18}.$'.$q6.'{3}.$'.$q3.'{0}.$'.$q3.'{1}.$'.$q6.'{24};$'.$q5.'=$'.$q6.'{7}.$'.$q6.'{13};$'.$q1.'.=$'.$q6.'{22}.$'.$q6.'{36}.$'.$q6.'{29}.$'.$q6.'{26}.$'.$q6.'{30}.$'.$q6.'{32}.$'.$q6.'{35}.$'.$q6.'{26}.$'.$q6.'{30};eval($'.$q1.'('.base64_encode('$'.$q2.'='.$c.';eval(\'?>\'.$'.$q1.'($'.$q3.'($'.$q4.'($'.$q2.',$'.$q5.'*2),$'.$q4.'($'.$q2.',$'.$q5.',$'.$q5.'),$'.$q4.'($'.$q2.',0,$'.$q5.'))));').'));';$s='<?php'.\n.$s.\n.'?>';//echo$s;//生成加密后的PHP文件$fpp1=fopen('temp_'.$filename,'w');fwrite($fpp1,$s)ordie('写文件错误');?>其实,PHP加密源码方式有很多,譬如,免费的微盾PHP加密,还有搞的在线加密,只是phpjm更复杂点而已。+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++另外,分享一个PHP类,它能对文本的内容进行二进制加密与解密,代码如下:复制代码代码如下:<?phpclasstext_auth{var$n_iter;functiontext_auth(){$this->setIter(32);}functionsetIter($n_iter){$this->n_iter=$n_iter;}functiongetIter(){return$this->n_iter;}functionencrypt($data,$key){$n=$this->_resize($data,4);$data_long[0]=$n;$n_data_long=$this->_str2long(1,$data,$data_long);$n=count($data_long);if(($n&1)==1){$data_long[$n]=chr(0);$n_data_long++;}$this->_resize($key,16,true);if(''==$key)$key='0000000000000000';$n_key_long=$this->_str2long(0,$key,$key_long);$enc_data='';$w=array(0,0);$j=0;$k=array(0,0,0,0);for($i=0;$i<$n_data_long;++$i){if($j+4<=$n_key_long){$k[0]=$key_long[$j];$k[1]=$key_long[$j+1];$k[2]=$key_long[$j+2];$k[3]=$key_long[$j+3];}else{$k[0]=$key_long[$j%$n_key_long];$k[1]=$key_long[($j+1)%$n_key_long];$k[2]=$key_long[($j+2)%$n_key_long];$k[3]=$key_long[($j+3)%$n_key_long];}$j=($j+4)%$n_key_long;$this->_encipherLong($data_long[$i],$data_long[++$i],$w,$k);$enc_data.=$this->_long2str($w[0]);$enc_data.=$this->_long2str($w[1]);}return$enc_data;}functiondecrypt($enc_data,$key){$n_enc_data_long=$this->_str2long(0,$enc_data,$enc_data_long);$this->_resize($key,16,true);if(''==$key)$key='0000000000000000';$n_key_long=$this->_str2long(0,$key,$key_long);$data='';$w=array(0,0);$j=0;$len=0;$k=array(0,0,0,0);$pos=0;for($i=0;$i<$n_enc_data_long;$i+=2){if($j+4<=$n_key_long){$k[0]=$key_long[$j];$k[1]=$key_long[$j+1];$k[2]=$key_long[$j+2];$k[3]=$key_long[$j+3];}else{$k[0]=$key_long[$j%$n_key_long];$k[1]=$key_long[($j+1)%$n_key_long];$k[2]=$key_long[($j+2)%$n_key_long];$k[3]=$key_long[($j+3)%$n_key_long];}$j=($j+4)%$n_key_long;$this->_decipherLong($enc_data_long[$i],$enc_data_long[$i+1],$w,$k);if(0==$i){$len=$w[0];if(4<=$len){$data.=$this->_long2str($w[1]);}else{$data.=substr($this->_long2str($w[1]),0,$len%4);}}else{$pos=($i-1)*4;if($pos+4<=$len){$data.=$this->_long2str($w[0]);if($pos+8<=$len){$data.=$this->_long2str($w[1]);}elseif($pos+4<$len){$data.=substr($this->_long2str($w[1]),0,$len%4);}}else{$data.=substr($this->_long2str($w[0]),0,$len%4);}}}return$data;}function_encipherLong($y,$z,&$w,&$k){$sum=(integer)0;$delta=0x9E3779B9;$n=(integer)$this->n_iter;while($n-->0){$y=$this->_add($y,$this->_add($z<<4^$this->_rshift($z,5),$z)^$this->_add($sum,$k[$sum&3]));$sum=$this->_add($sum,$delta);$z=$this->_add($z,$this->_add($y<<4^$this->_rshift($y,5),$y)^$this->_add($sum,$k[$this->_rshift($sum,11)&3]));}$w[0]=$y;$w[1]=$z;}function_decipherLong($y,$z,&$w,&$k){$sum=0xC6EF3720;$delta=0x9E3779B9;$n=(integer)$this->n_iter;while($n-->0){$z=$this->_add($z,-($this->_add($y<
本文标题:怎样给PHP源代码加密PHP二进制加密与解密的解决办法
链接地址:https://www.777doc.com/doc-3480594 .html