您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 兴安分类信息网,免费分类信息发布

php代码的加密解密

2024/3/21 19:14:35发布8次查看
php 代码加密类 initialvar(); //echo hello \n; } /* *@input $property_name,$value *@output * 魔法方法,对变量进行设置值;可根据需求进行处理。若直接去除if判断表示可用设置任何属性的值,包括不存在的属性; */ public function __set($property_name,$value){ //定义过的变量; if(isset($this->$property_name)){ $this->$property_name = $value; }else{ //异常处理,处理未声明的变量赋值;可根据需求进行处理。 throw new exception(property does not exist); } } //魔法方法 取出变量的值; public function __get($property_name){ if(isset($this->$property_name)){ return $this->$property_name; }else{ //throw new exception(property does not exist); return null; } } //取随机排序 private function randabc($length=){//随机排序取回 $str=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz; return str_shuffle($str); } //对明文内容进行加密处理 private function ciphertext($filename){ //$filename='index.php'; $t_k1=$this->randabc(); $t_k2=$this->randabc(); $vstr=file_get_contents($filename); $v1=base64_encode($vstr); $c=strtr($v1,$t_k1,$t_k2); $this->c=$t_k1.$t_k2.$c; return $this; } //初始化变量 private function initialvar(){ $this->q1=o00o0o;//base64_decode $this->q2=o0o000;//$c(原文经过strtr置换后的密文,由 目标字符+替换字符+base64_encode(‘原文内容’)构成) $this->q3=o0oo00;//strtr $this->q4=oo0o00;//substr $this->q5=oo0000;//52 $this->q6=o00oo0;//urldecode解析过的字符串(n1zb/ma5\vt0i28-pxuqy*6%6crkdg9_ehcswo4+f37j) } //生成加密后的模板(复杂版本); private function model(){ //$c = $this->c; //$this->initialvar(); $this->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);$'. $this->q1.'=$'.$this->q6.'{3}.$'.$this->q6.'{6}.$'.$this->q6.'{33}.$'.$this->q6.'{30};$'.$this->q3.'=$'.$this->q6.'{33}.$'.$this->q6.'{10}.$' .$this->q6.'{24}.$'.$this->q6.'{10}.$'.$this->q6.'{24};$'.$this->q4.'=$'.$this->q3.'{0}.$'.$this->q6.'{18}.$'.$this->q6.'{3}.$'.$this->q3.'{0} .$'.$this->q3.'小贝.$'.$this->q6.'{24};$'.$this->q5.'=$'.$this->q6.'{7}.$'.$this->q6.'{13};$'.$this->q1.'.=$'.$this->q6.'{22}.$'.$this->q6.'{36} .$'.$this->q6.'{29}.$'.$this->q6.'{26}.$'.$this->q6.'{30}.$'.$this->q6.'{32}.$'.$this->q6.'{35}.$'.$this->q6.'{26}.$'.$this->q6.'{30}; eval($'.$this->q1.'('.base64_encode('$'.$this->q2.'='.$this->c.'; eval(\'?>\'.$'.$this->q1.'($'.$this->q3.'($'.$this->q4.'($'.$this->q2.',$'.$this->q5.'*2),$'.$this->q4.'($'.$this->q2.',$'.$this->q5.',$'.$this->q5.'), $'.$this->q4.'($'.$this->q2.',0,$'.$this->q5.'))));').'));?>'; return $this; } //创建加密文件 private function build($target){ //$this->encodes(./index.php); //$this->model(); $fpp1 = fopen($target,'w'); fwrite($fpp1,$this->s) or die('写入是失败!'); fclose($fpp1); return $this; } //加密处理 连贯操作 public function encode($file,$target){ //$file = index.php; //连贯操作其实就是利用函数处理完后返回自身 $this->ciphertext($file)->model()->build($target); echo 'encode------'.$target.'-----ok
'; } //解密 public function decode($file,$target=''){ //读取要解密的文件 $fpp1 = file_get_contents($file); $this->decodemode($fpp1)->build($target); echo 'decode------'.$target.'-----ok
'; } //解密模板,得到解密后的文本 private function decodemode($fpp1){ //以eval为标志 截取为数组,前半部分为密文中的替换掉的函数名,后半部分为密文 $m = explode('eval',$fpp1); //对系统函数的替换部分进行执行,得到系统变量 $varstr = substr($m[0],strpos($m[0],'$')); //执行后,后续就可以使用替换后的系统函数名 eval($varstr); //判断是否有密文 if(!isset($m[1])){ return $this; } //对密文进行截取 {$this->q4} substr $star = strripos($m[1],'('); $end = strpos($m[1],')'); $str = ${$this->q4}($m[1],$star,$end); //对密文解密 {$this->q1} base64_decode $str = ${$this->q1}($str); //截取出解密后的 核心密文 $evallen = strpos($str,'eval'); $str = substr($str,0,$evallen); //执行核心密文 使系统变量被赋予值 $o0o000 eval($str); //并不能将如下段封装,因为 ${$this->qn} 并不能在全文中起作用 $this->s = ${$this->q1}( ${$this->q3}( ${$this->q4}( ${$this->q2},${$this->q5}*2 ), ${$this->q4}( ${$this->q2},${$this->q5},${$this->q5} ), ${$this->q4}( ${$this->q2},0,${$this->q5} ) ) ); return $this; } //递归读取并创建目标目录结构 private function targetdir($target){ if(!empty($target) ) { if(!file_exists($target)){ mkdir($target,0777,true); }else{ chmod($target,0777); } } } //递归解密 对指定文件夹下的php文件解密 public function decodedir($source,$target=){ if(is_dir($source)){ $this->targetdir($target); $dir = opendir($source); while(false!=$file=readdir($dir)) { //列出所有文件并去掉'.'和'..' 此处用的实例为thinkphp框架,所以默认排除里thinkphp目录,用户可以按照自己的需求设置 if($file!='.' && $file!='..' && $file !='thinkphp') { $path = $target.directory_separator.$file; $sourcepath = $source.directory_separator.$file; $this->decodedir($sourcepath,$path); } } }else if(is_file($source)){ $extension=substr($source,strrpos($source,'.')+1); if(strtolower($extension)=='php'){ $this->decode($source,$target); }else{ //不是php的文件不处理 copy($source, $target); } //return; } } //递归加密 对指定文件夹下的php文件加密 public function encodedir($source,$target){ if(is_dir($source)){ $this->targetdir($target); $dir = opendir($source); while(false!=$file=readdir($dir)) { //列出所有文件并去掉'.'和'..' if($file!='.' && $file!='..' && $file !='thinkphp') { $path = $target.directory_separator.$file; $sourcepath = $source.directory_separator.$file; $this->encodedir($sourcepath,$path); } } }else if(is_file($source)){ $extension=substr($source,strrpos($source,'.')+1); if(strtolower($extension)=='php'){ $this->encode($source,$target); }else{ copy($source, $target); } } } } $ob = new encryption(); $ob->source = /var/www/bookreservation; $ob->target = /var/www/jiami/bookreservation; //解密指定文件 //$ob->decode('d:\\php\\www\\workspace\\weixin2\\application\\home\\controller\\indexcontroller.class.php'); //$ob->decode('jiami.php'); //$ob->decode('dam6.php'); //对一个指定的文件目录进行加密 $ob->encodedir($ob->source,$ob->target); //对一个指定的文件目录进行解密 $ob->decodedir($ob->target,/var/www/jiami/bookreservationd);
复制代码
加密解密, php
兴安分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录