PHP base64+gzinflate压缩编码和解码代码

yipeiwu_com5年前PHP代码库
base64+gzinflate压缩编码(加密)过的文件通常是以 <? eval(gzinflate(base64_decode( 为头的一个php文件。以下我们给出了相关的编码解码(加密解密)代码。

压缩编码(加密)代码:
复制代码 代码如下:

<?php
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);// 判断文件是否已经被编码处理
$pos = strpos($contents,'/*Protected by 草名 http://www.crazyi.cn Cryptation*/');
if(false === $pos || $pos>100){ // 去除PHP文件注释和空白,减少文件大小
$contents = php_strip_whitespace($filename);
// 去除PHP头部和尾部标识
$headerPos = strpos($contents,'<?php');
$footerPos = strrpos($contents,'?>');
$contents = substr($contents,$headerPos+5,$footerPos-$headerPos);
$encode = base64_encode(gzdeflate($contents));// 开始编码
$encode = '<?php'." /*Protected by 草名 http://www.crazyi.cn Cryptation*/\n eval(gzinflate(base64_decode(".$encode.")));\n /*Reverse engineering is illegal and strictly prohibited- (C)草名 Cryptation 2008*/ \n?>";
return file_put_contents($filename,$encode);
}
}
return false;
}
//调用函数
$filename='g:\我的文档\桌面\test.php';
encode_file_contents($filename);
?>
<?php
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);// 判断文件是否已经被编码处理
$pos = strpos($contents,'/*Protected by 草名 http://www.crazyi.cn Cryptation*/');
if(false === $pos || $pos>100){ // 去除PHP文件注释和空白,减少文件大小
$contents = php_strip_whitespace($filename);
// 去除PHP头部和尾部标识
$headerPos = strpos($contents,'<?php');
$footerPos = strrpos($contents,'?>');
$contents = substr($contents,$headerPos+5,$footerPos-$headerPos);
$encode = base64_encode(gzdeflate($contents));// 开始编码
$encode = '<?php'." /*Protected by 草名 http://www.crazyi.cn Cryptation*/\n eval(gzinflate(base64_decode(".$encode.")));\n /*Reverse engineering is illegal and strictly prohibited- (C)草名 Cryptation 2008*/ \n?>";
return file_put_contents($filename,$encode);
}
}
return false;
}
//调用函数
$filename='g:\我的文档\桌面\test.php';
encode_file_contents($filename);
?>


压缩解码(解密)代码:
复制代码 代码如下:

<?php
$Code = '这里填写要解密的编码'; // base64编码
$File = 'test.php';//解码后保存的文件
$Temp = base64_decode($Code);
$temp = gzinflate($Temp);
$FP = fopen($File,"w");
fwrite($FP,$temp);
fclose($FP);
echo "解密成功!";
?>

相关文章

RSA实现JS前端加密与PHP后端解密功能示例

RSA实现JS前端加密与PHP后端解密功能示例

本文实例讲述了RSA实现JS前端加密与PHP后端解密功能。分享给大家供大家参考,具体如下: web前端,用户注册与登录,不能直接以明文形式提交用户密码,容易被截获,这时就引入RSA。 前...

php解决约瑟夫环算法实例分析

本文实例讲述了php解决约瑟夫环算法。分享给大家供大家参考,具体如下: 今天偶遇一道算法题 “约瑟夫环”是一个数学的应用问题:一群猴子排成一圈,按1,2,…,n依次编号。然后从第1只开...

php数组函数序列之array_keys() - 获取数组键名

array_keys() 定义和用法 array_keys() 函数返回包含数组中所有键名的一个新数组。 如果提供了第二个参数,则只返回键值为该值的键名。 如果 strict 参数指定为...

PHP实现动态删除XML数据的方法示例

PHP实现动态删除XML数据的方法示例

本文实例讲述了PHP实现动态删除XML数据的方法。分享给大家供大家参考,具体如下: 前面介绍了动态添加XML数据的方法,这里在原有Message_XML类的基础上稍作改进,实现动态删除x...

php无序树实现方法

php无序树实现方法

本文实例讲述了php无序树实现方法。分享给大家供大家参考。具体如下: 运行效果如下图所示: php代码如下: <?php /* 用php写的无序树 */ cla...