PHP Implementation of PHP code encryption and decryption _php tutorial

Source: Internet
Author: User
Tags decrypt

PHP Implementation of PHP code encryption and decryption


PHP code Encryption class, we can modify according to their own needs, the original class, such as the previous encryption and decryption class has been modified, I hope to share to you. This time in Ubuntu Test no problem, with the previous version of the difference is that this version of the more universal.

    
 Initialvar ();          echo "Hello \ n"; }/* * @input $property _name, $value * @output * Magic method, set the value of the variable, can be processed according to requirements.              If the direct removal if judgment indicates the value of any property that can be set, including the nonexistent attribute; */Public Function __set ($property _name, $value) {//defined variables;              if (Isset ($this, $property _name)) {$this, $property _name = $value;                  }else{//exception handling, handling undeclared variable assignments, can be processed on demand.              throw new Exception ("does not exist"); }}//Magic method takes out the value of the variable, public function __get ($property _name) {if (Isset ($this $prop              Erty_name) {return $this, $property _name;                  }else{//throw New Exception ("Property does not exist");              return NULL; }}//Take random sort Private function randabc ($length = "") {//random sort fetch $STR = "Abcdefghijklmnopqrst UVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ ";           Return Str_shuffle ($STR);              }//Encrypt plaintext content with private function ciphertext ($filename) {//$filename = ' index.php ';              $T _k1= $this->randabc ();              $T _k2= $this->randabc ();              $vstr =file_get_contents ($filename);              $v 1=base64_encode ($VSTR);            $c =strtr ($v 1, $T _k1, $T _k2);              $this->c= $T _k1. $T _k2. $c;          return $this; }//Initialize variable private function Initialvar () {$this->q1= "o00o0o";//base64_decode $              This->q2= "o0o000";//$c (ciphertext after strtr substitution, consisting of the target character + replacement character +base64_encode (' original content ') $this->q3= "o0oo00";//strtr $this->q4= "oo0o00",//substr $this->q5= "OO0000",//52 $this->q6= "O00oo0";//u          Rldecode parsed string (n1zb/ma5\vt0i28-pxuqy*6%6crkdg9_ehcswo4+f37j)}//Generate an encrypted template (complex version);            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. ' {1}.$ '. $this->q6. ' {24};$ '. $this->q5. ' =$ '. $this->q6. ' {7}.$ '. $this->q6. ' {13};$ '. $this->q1. =$ '. $this->q6. ' {22}.$ '. $this->q6. ' {->Q6}. $ '. $this. ' {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. ' * *), $ '. $this->q4. ' ($ '. $this->q2. ', $ '. $this->q5. ', $ '. $this->q5. '), $ '. $this->q4. ' ($ '. $this->q2. ', 0,$ '. $this->q5. ')))));              > ';          return $this;              }//Create Encrypted File Private function build ($target) {//$this->encodes ("./index.php");              $this->model ();              $FPP 1 = fopen ($target, ' w '); Fwrite ($FPP 1, $this->s) or Die (' Write is failed!            ');            Fclose ($FPP 1);          return $this;              }//cryptographic processing of the public function encode ($file, $target) {//$file = "index.php";            Coherent operation is actually the use of functions to return to their own $this->ciphertext ($file)->model ()->build ($target);          echo ' encode------'. $target. '-----OK '; }//Decrypt Public function decode ($file, $target = ") {//Read the file to be decrypted $FPP 1 = file_get_conte            NTS ($file); $this->decodemode ($FPP 1)->buILD ($target);        Echo ' decode------'. $target. '-----OK ';            }//Decrypt the template, get the decrypted text of the private function Decodemode ($FPP 1) {//with the eval as the flag to intercept the array, the first half of the ciphertext is replaced by the function name, the second half is ciphertext            $m = explode (' eval ', $FPP 1);            The replacement part of the system function is executed to get the system variable $VARSTR = substr ($m [0],strpos ($m [0], ' $ '));            After execution, the replacement system function name eval ($VARSTR) can be used later;            Determine if there is a ciphertext if (!isset ($m [1])) {return $this;            }//Intercept the ciphertext {$this->q4} substr $star = Strripos ($m [1], ' (');            $end = Strpos ($m [1], ') ');            $str = ${$this->q4} ($m [1], $star, $end);            Decrypt the ciphertext {$this->q1} base64_decode $str = ${$this->q1} ($STR);            Intercept the decrypted core cipher $evallen = Strpos ($str, ' eval ');            $str = substr ($str, 0, $evallen);            Performs core redaction to give the system variable a value $O 0o000 eval ($str); The following segment cannot be encapsulated because ${$this->QN} does not work in the full text $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,${$thi            S->Q5}));        return $this; }//recursively read and create the destination directory structure private function TargetDir ($target) {if (!empty ($target)) {if (                !file_exists ($target)) {mkdir ($target, 0777,true);                }else{chmod ($target, 0777); }}}//Recursively decrypt the PHP file under the specified folder to decrypt the public function Decodedir ($source, $target = "") {I                F (Is_dir ($source)) {$this->targetdir ($target);                  $dir = Opendir ($source); while (false!= $file =readdir ($dir)) {//list all files and remove '. '  and ' ... ' here is an example of the thinkphp framework, so the default excludes the thinkphp directory where the user can set the IF ($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{//Not PHP files do not process copy ($source, $target);              }//return; }}//recursive encryption to PHP files under the specified folder public function Encodedir ($source, $target) {if (Is_dir ($sour           CE)) {     $this->targetdir ($target);                  $dir = Opendir ($source); while (false!= $file =readdir ($dir)) {//list all files and remove '. '                    and ' ... ' 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"; Decrypts the specified file//$ob->decode (' d:\\php\\www\\workspace\\weixin2\\application\\home\\controller\\            IndexController.class.php ');      $ob->decode (' jiami.php ');      $ob->decode (' dam6.php ');    Encrypts a specified file directory $ob->encodedir ($ob->source, $ob->target); Decrypts a specified file directory $ob->decodedir ($ob->target, "/var/www/jiami/bookreservationd");


http://www.bkjia.com/PHPjc/989126.html www.bkjia.com true http://www.bkjia.com/PHPjc/989126.html techarticle PHP Implementation of PHP code encryption and decryption of PHP code encryption class, we can modify according to their own needs, the original class, such as the following, is the previous encryption and decryption class has a modification, hope to be divided ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.