Encryption method for PHP source code program_PHP tutorial

WBOY
Release: 2016-07-13 17:10:29
Original
864 people have browsed it

The article introduces two methods to encrypt the PHP program itself. Our common method is base64_encode(gzdeflate($contents)) to encrypt. The second method is rare and friends in need can also refer to it.

Example 1

}
return false;
}
//Call function
$filename='dam.php';
encode_file_contents($filename);
echo "OK, encryption completed!"
?>
The code is as follows
 代码如下 复制代码

function encode_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,' $footerPos = strrpos($contents,'?>');
$contents = substr($contents,$headerPos+5,$footerPos-$headerPos);
$encode = base64_encode(gzdeflate($contents));// 开始编码
$encode = '";
return file_put_contents($filename,$encode);

}
return false;
}
//调用函数
$filename='dam.php';
encode_file_contents($filename);
echo "OK,加密完成!"
?>

Copy code

 代码如下 复制代码

function RandAbc($length=""){//返回随机字符串
$str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
return str_shuffle($str);
}
$filename='dam.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=' '.$s.
'
?>';
echo "OK,加密完成!";
//生成 加密后的PHP文件
$fpp1 = fopen('dam.php','w');
fwrite($fpp1,$s) or die('写文件错误');
?>

function encode_file_contents($filename) {
$type=strtolower(substr(strrchr($filename,'.'),1));
if('php'==$type && is_file($filename) && is_writable($filename)){// If it is a PHP file and can be written, compress it and encode it
$contents = file_get_contents($filename); // Determine whether the file has been encoded
$contents = php_strip_whitespace($filename);
// Remove PHP header and trailer tags
$headerPos = strpos($contents,' $footerPos = strrpos($contents,'?>');
$contents = substr($contents,$headerPos+5,$footerPos-$headerPos);
$encode = base64_encode(gzdeflate($contents));//Start encoding
$encode = '";
return file_put_contents($filename,$encode);

The code is as follows Copy code
function RandAbc($length=""){//Return a random string
$str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
Return str_shuffle($str);
}
$filename='dam.php';
$T_k1=RandAbc();//Random key 1
$T_k2=RandAbc();//Random key 2
$vstr=file_get_contents($filename);//The file to be encrypted
$v1=base64_encode($vstr);
$c=strtr($v1,$T_k1,$T_k2);//Replace the corresponding characters according to the key.
$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=' '.$s.
'
?>';
echo "OK, encryption completed!";
//Generate encrypted PHP file
$fpp1 = fopen('dam.php','w');
fwrite($fpp1,$s) or die('Error writing file');
?>
http://www.bkjia.com/PHPjc/629667.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629667.htmlTechArticleThe article introduces two methods to encrypt the PHP program itself. Our common method is base64_encode(gzdeflate($contents) ) is encrypted in this way. The second method is rare. Friends in need can also participate...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!