PHP base64+gzinflate压缩编码和解码代码_php技巧
程序员文章站
2022-06-16 09:05:01
...
base64+gzinflate压缩编码(加密)过的文件通常是以 eval(gzinflate(base64_decode( 为头的一个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,'$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='g:\我的文档\桌面\test.php';
encode_file_contents($filename);
?>
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,'$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='g:\我的文档\桌面\test.php';
encode_file_contents($filename);
?>
压缩解码(解密)代码:
$Code = '这里填写要解密的编码'; // base64编码
$File = 'test.php';//解码后保存的文件
$Temp = base64_decode($Code);
$temp = gzinflate($Temp);
$FP = fopen($File,"w");
fwrite($FP,$temp);
fclose($FP);
echo "解密成功!";
?>
压缩编码(加密)代码:
复制代码 代码如下:
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,'$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='g:\我的文档\桌面\test.php';
encode_file_contents($filename);
?>
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,'$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='g:\我的文档\桌面\test.php';
encode_file_contents($filename);
?>
压缩解码(解密)代码:
复制代码 代码如下:
$Code = '这里填写要解密的编码'; // base64编码
$File = 'test.php';//解码后保存的文件
$Temp = base64_decode($Code);
$temp = gzinflate($Temp);
$FP = fopen($File,"w");
fwrite($FP,$temp);
fclose($FP);
echo "解密成功!";
?>
推荐阅读
-
PHP mb_convert_encoding 获取字符串编码类型实现代码_php技巧
-
php下检测字符串是否是utf8编码的代码_php技巧
-
PHP iconv 解决utf-8和gb2312编码转换问题_php技巧
-
php简单对象与数组的转换函数代码(php多层数组和对象的转换)_php技巧
-
PHP解码unicode编码的中文字符代码分享_php实例
-
PHP操作文件类的函数代码(文件和文件夹创建,复制,移动和删除)_php技巧
-
php制作unicode解码工具(unicode编码转换器)代码分享_PHP
-
使用php判断浏览器的类型和语言的函数代码_php技巧
-
php的chr和ord函数实现字符加减乘除运算实现代码_php技巧
-
php制作unicode解码工具(unicode编码转换器)代码分享