phpに基づいて実装されたphpコード暗号化復号クラスの完全なインスタンス
10117 ワード
この例では、phpに基づいて実装されるphpコード暗号化復号クラスについて説明する.皆さんの参考にしてください.具体的には以下の通りです.
phpコード暗号化クラスは、自分のニーズに合わせて修正することができます.元のクラスは以下のように、ubuntuでテストしても問題ありません.
PS:暗号解読に興味のある方は、当駅のオンラインツールも参考にしてください.
パスワードセキュリティのオンライン検出:http://tools.jb51.net/password/my_password_safe
高強度パスワードジェネレータ:http://tools.jb51.net/password/CreateStrongPassword
MD 5オンライン暗号化ツール:http://tools.jb51.net/password/CreateMD5Password
迅雷、急行、サイクロンURL暗号化/復号ツール:http://tools.jb51.net/password/urlrethunder
オンラインハッシュ/ハッシュアルゴリズム暗号化ツール:http://tools.jb51.net/password/hash_encrypt
PHPに関する内容についてもっと兴味のある読者は、「php暗号化方法総括」、「PHP符号化とトランスコード操作テクニック総括」、「phpオブジェクト向けプログラム设计入门チュートリアル」、「PHP数学演算テクニック総括」、「PHP配列(Array)操作テクニック大全」、「php文字列(string)用法総括」、「PHPデータ构造とアルゴリズムチュートリアル」、「phpプログラム設計アルゴリズム総括」、「php正規表現用法総括」、および「phpよく見られるデータベース操作テクニック要約」
ここで述べたことが皆さんのPHPプログラム設計に役立つことを願っています.
phpコード暗号化クラスは、自分のニーズに合わせて修正することができます.元のクラスは以下のように、ubuntuでテストしても問題ありません.
initialVar();
//echo "hello
";
}
/*
*@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.'{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;
}
//
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");
PS:暗号解読に興味のある方は、当駅のオンラインツールも参考にしてください.
パスワードセキュリティのオンライン検出:http://tools.jb51.net/password/my_password_safe
高強度パスワードジェネレータ:http://tools.jb51.net/password/CreateStrongPassword
MD 5オンライン暗号化ツール:http://tools.jb51.net/password/CreateMD5Password
迅雷、急行、サイクロンURL暗号化/復号ツール:http://tools.jb51.net/password/urlrethunder
オンラインハッシュ/ハッシュアルゴリズム暗号化ツール:http://tools.jb51.net/password/hash_encrypt
PHPに関する内容についてもっと兴味のある読者は、「php暗号化方法総括」、「PHP符号化とトランスコード操作テクニック総括」、「phpオブジェクト向けプログラム设计入门チュートリアル」、「PHP数学演算テクニック総括」、「PHP配列(Array)操作テクニック大全」、「php文字列(string)用法総括」、「PHPデータ构造とアルゴリズムチュートリアル」、「phpプログラム設計アルゴリズム総括」、「php正規表現用法総括」、および「phpよく見られるデータベース操作テクニック要約」
ここで述べたことが皆さんのPHPプログラム設計に役立つことを願っています.