欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于php實(shí)現(xiàn)的php代碼加密解密類完整實(shí)例

 更新時(shí)間:2016年10月12日 08:56:50   作者:edit02_lz  
這篇文章主要介紹了基于php實(shí)現(xiàn)的php代碼加密解密類,結(jié)合完整實(shí)例形式分析了php針對(duì)php代碼進(jìn)行加密與解密的完整流程,以及加密解密類的使用方法,需要的朋友可以參考下

本文實(shí)例講述了基于php實(shí)現(xiàn)的php代碼加密解密類。分享給大家供大家參考,具體如下:

php 代碼加密類,大家可以根據(jù)自己的需求進(jìn)行修改,原類如下,該實(shí)例在ubuntu下測(cè)試沒有問題。

<?php
class Encryption{
    private $c='';//存儲(chǔ)密文
    private $s='',$q1,$q2,$q3,$q4,$q5,$q6;//存儲(chǔ)生成的加密后的文件內(nèi)容
    //如果不設(shè)置一個(gè)值,isset會(huì)表示不存在;
    private $file='';//讀取文件的路徑
    private $source='',$target='';
    //構(gòu)造函數(shù),實(shí)例化時(shí)調(diào)用初始化全局變量;
    public function __construct(){
      //初始化全局變量
      $this->initialVar();
      //echo "hello \n";
    }
    /*
    *@input $property_name,$value
    *@output
    *  魔法方法,對(duì)變量進(jìn)行設(shè)置值;可根據(jù)需求進(jìn)行處理。若直接去除if判斷表示可用設(shè)置任何屬性的值,包括不存在的屬性;
    */
    public function __set($property_name,$value){
      //定義過的變量;
      if(isset($this->$property_name)){
        $this->$property_name = $value;
      }else{
        //異常處理,處理未聲明的變量賦值;可根據(jù)需求進(jìn)行處理。
        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;
      }
    }
    //取隨機(jī)排序
    private function RandAbc($length=""){//隨機(jī)排序取回
     $str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
     return str_shuffle($str);
    }
    //對(duì)明文內(nèi)容進(jìn)行加密處理
    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(原文經(jīng)過strtr置換后的密文,由 目標(biāo)字符+替換字符+base64_encode(‘原文內(nèi)容')構(gòu)成)
      $this->q3="O0OO00";//strtr
      $this->q4="OO0O00";//substr
      $this->q5="OO0000";//52
      $this->q6="O00OO0";//urldecode解析過的字符串(n1zb/ma5\vt0i28-pxuqy*6%6Crkdg9_ehcswo4+f37j)
    }
    //生成加密后的模板(復(fù)雜版本);
    private function model(){
      //$c = $this->c;
      //$this->initialVar();
      $this->s='<?php $'.$this->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.'{1}.$'.$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;
    }
    //創(chuàng)建加密文件
    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";
      //連貫操作其實(shí)就是利用函數(shù)處理完后返回自身
      $this->ciphertext($file)->model()->build($target);
      echo 'encode------'.$target.'-----ok<br/>';
    }
    //解密
    public function decode($file,$target=''){
      //讀取要解密的文件
      $fpp1 = file_get_contents($file);
      $this->decodeMode($fpp1)->build($target);
      echo 'decode------'.$target.'-----ok<br/>';
    }
    //解密模板,得到解密后的文本
    private function decodeMode($fpp1){
      //以eval為標(biāo)志 截取為數(shù)組,前半部分為密文中的替換掉的函數(shù)名,后半部分為密文
      $m = explode('eval',$fpp1);
      //對(duì)系統(tǒng)函數(shù)的替換部分進(jìn)行執(zhí)行,得到系統(tǒng)變量
      $varStr = substr($m[0],strpos($m[0],'$'));
      //執(zhí)行后,后續(xù)就可以使用替換后的系統(tǒng)函數(shù)名
      eval($varStr);
      //判斷是否有密文
      if(!isset($m[1])){
        return $this;
      }
      //對(duì)密文進(jìn)行截取 {$this->q4} substr
      $star = strripos($m[1],'(');
      $end = strpos($m[1],')');
      $str = ${$this->q4}($m[1],$star,$end);
      //對(duì)密文解密 {$this->q1} base64_decode
      $str = ${$this->q1}($str);
      //截取出解密后的 核心密文
      $evallen = strpos($str,'eval');
      $str = substr($str,0,$evallen);
      //執(zhí)行核心密文 使系統(tǒng)變量被賦予值 $O0O000
      eval($str);
      //并不能將如下段封裝,因?yàn)?${$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;
    }
    //遞歸讀取并創(chuàng)建目標(biāo)目錄結(jié)構(gòu)
    private function targetDir($target){
      if(!empty($target) ) {
        if(!file_exists($target)){
          mkdir($target,0777,true);
        }else{
          chmod($target,0777);
        }
      }
    }
    //遞歸解密 對(duì)指定文件夾下的php文件解密
    public function decodeDir($source,$target=""){
      if(is_dir($source)){
        $this->targetDir($target);
        $dir = opendir($source);
        while(false!=$file=readdir($dir))
        {
          //列出所有文件并去掉'.'和'..' 此處用的實(shí)例為thinkphp框架,所以默認(rèn)排除里Thinkphp目錄,用戶可以按照自己的需求設(shè)置
          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;
      }
    }
    //遞歸加密 對(duì)指定文件夾下的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');
//對(duì)一個(gè)指定的文件目錄進(jìn)行加密
$ob->encodeDir($ob->source,$ob->target);
//對(duì)一個(gè)指定的文件目錄進(jìn)行解密
$ob->decodeDir($ob->target,"/var/www/jiami/bookReservationD");

PS:關(guān)于加密解密感興趣的朋友還可以參考本站在線工具:

密碼安全性在線檢測(cè):
http://tools.jb51.net/password/my_password_safe

高強(qiáng)度密碼生成器:
http://tools.jb51.net/password/CreateStrongPassword

MD5在線加密工具:
http://tools.jb51.net/password/CreateMD5Password

迅雷、快車、旋風(fēng)URL加密/解密工具:
http://tools.jb51.net/password/urlrethunder

在線散列/哈希算法加密工具:
http://tools.jb51.net/password/hash_encrypt

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php加密方法總結(jié)》、《PHP編碼與轉(zhuǎn)碼操作技巧匯總》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計(jì)算法總結(jié)》、《php正則表達(dá)式用法總結(jié)》、及《php常見數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • PHP單文件上傳原理及上傳函數(shù)的封裝操作示例

    PHP單文件上傳原理及上傳函數(shù)的封裝操作示例

    這篇文章主要介紹了PHP單文件上傳原理及上傳函數(shù)的封裝操作,結(jié)合實(shí)例形式詳細(xì)分析了php文件上傳的原理、步驟及相關(guān)函數(shù)封裝操作技巧,需要的朋友可以參考下
    2019-09-09
  • PHP使用Mysql事務(wù)實(shí)例解析

    PHP使用Mysql事務(wù)實(shí)例解析

    這篇文章主要介紹了PHP使用Mysql事務(wù)的用法,是PHP數(shù)據(jù)庫(kù)程序設(shè)計(jì)中非常重要的實(shí)用操作技巧,需要的朋友可以參考下
    2014-09-09
  • 10個(gè)簡(jiǎn)化PHP開發(fā)的工具

    10個(gè)簡(jiǎn)化PHP開發(fā)的工具

    這篇文章主要介紹了10個(gè)簡(jiǎn)化PHP開發(fā)的工具,都是今年比較熱門和使用的,需要的朋友可以參考下
    2014-12-12
  • 推薦Discuz!5的PHP代碼高亮顯示與實(shí)現(xiàn)可運(yùn)行代碼

    推薦Discuz!5的PHP代碼高亮顯示與實(shí)現(xiàn)可運(yùn)行代碼

    推薦Discuz!5的PHP代碼高亮顯示與實(shí)現(xiàn)可運(yùn)行代碼...
    2007-03-03
  • php遞歸刪除指定文件夾的方法小結(jié)

    php遞歸刪除指定文件夾的方法小結(jié)

    這篇文章主要介紹了php遞歸刪除指定文件夾的方法,實(shí)例總結(jié)了兩種常用的遞歸刪除文件夾的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-04-04
  • 淺析PHP繪圖技術(shù)

    淺析PHP繪圖技術(shù)

    本篇文章是對(duì)PHP繪圖技術(shù)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-07-07
  • 請(qǐng)php正則走開

    請(qǐng)php正則走開

    玩PHP玩了幾年了,在剛剛接觸PHP的時(shí)候感覺正則真的很洋氣,我想替換啥就替換啥。然而隨著工作的推移,漸漸對(duì)正則開發(fā)反感起來,正則的速度太慢了,而且特占內(nèi)存。在一個(gè)群里有個(gè)網(wǎng)友說,正則速度快,正則簡(jiǎn)單,正則開發(fā)效率高。我并沒有與他爭(zhēng)辯,因?yàn)槲覄倓傋鯬HP的時(shí)候也是這樣的想法。但是正則真的那么好嗎?
    2008-03-03
  • PHP借助phpmailer發(fā)送郵件

    PHP借助phpmailer發(fā)送郵件

    phpmailer是一款免費(fèi)的php郵件發(fā)送插件,我們可以利用phpmailer登錄到我們指定的郵件然后再利用這個(gè)郵件給我們自動(dòng)發(fā)郵件了,這個(gè)現(xiàn)在免費(fèi)的郵箱像163,sina都支持,好了費(fèi)話不說多了來看看一段phpmainer 163郵件發(fā)送郵件吧。
    2015-05-05
  • php中JSON的使用方法

    php中JSON的使用方法

    json常用來作為數(shù)據(jù)交換的一種格式,和xml相比體積更小。缺點(diǎn)就是層級(jí)關(guān)系不明顯不大容易被理解。php中生成json要借助array和json_encode,json_decode一起使用。越復(fù)雜的json嵌套的數(shù)組越多,下面我們來仔細(xì)探討下這個(gè)問題。
    2015-04-04
  • php微信開發(fā)接入

    php微信開發(fā)接入

    這篇文章主要為大家詳細(xì)介紹了php微信開發(fā)接入,通過檢驗(yàn)signature對(duì)請(qǐng)求進(jìn)行校驗(yàn),感興趣的小伙伴們可以參考一下
    2016-08-08

最新評(píng)論