很多站长朋友们都不太清楚phpgzip解密,今天小编就来给大家整理phpgzip解密,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 PHP常用加密解密方法 2、 如何加密解密php源代码 3、 请高手们帮我解密一段php源码 4、 PHP文件如何解密 5、 请教php源码加密及解密问题 6、 php怎样实现对zip文件的加密和解密 PHP常用加密解密方法作者/上善若水
1.md5(string $str,bool $flag = false);
$flag = false 默认返回32位的16进至数据散列值
$flag = true 返回原始流数据
2.sha1($string,$flag = false)
$flag = false 默认返回40位的16进至数据散列值
true 返回原始流数据
3.hash(string $algo,srting $str,bool $flag);
$algo : 算法名称,可通过hash_algos()函数获取所有hash加密的算法
如:md5,sha1等,采用md5,sha1加密所得结果和1,2两种方式结 果相同。
$flag = false 默认返回16进至的数据散列值,具体长度根据算法不同
而不同。
true 返回原始流数据。
4.crypt(string $str,$string $salt);
函数返回使用 DES、Blowfish 或 MD5 算法加密的字符串。
具体算法依赖于PHP检查之后支持的算法和$salt的格式和长度,当 然具体结果也和操作系统有关。比较结果采用 hash_equals($crypted,crypt($input,$salt));//且salt值相同
Password_verify($str,$crypted);
5.password_hash ( string $str, integer $algo [, array $options ] )
函数返回哈希加密后的密码字符串, password_hash() 是crypt()的 一个简单封装
$algo : 算法 PASSWORD_DEFAULT ,PASSWORD_BCRYPT
$options = [
“cost”=>10,//指明算法递归的层数,
“salt”=>“xxadasdsad”//加密盐值,即将被遗 弃,采用系统自动随机生成安全性更高
];
使用的算法、cost 和盐值作为哈希的一部分返回
Password_verify($str,$hashed);
6.base64_encode(string $str)
设计此种编码是为了使二进制数据可以通过非纯 8-bit 的传输层 传输,例如电子邮件的主体。base64_decode(string $encoded)
可以进行解码;
7.mcrypt_encrypt ( string $cipher , string $key , string $data ,
string $mode [, string $iv ] )
mcrypt_decrypt ( string $cipher , string $key , string $crypted ,
string $mode [, string $iv ] )
$ciper:加密算法,mcrypt_list_algorithms()可以获取该函数所有支持的算法
如MCRYPT_DES(“des”),MCRYPT_RIJNDAEL_128(“rijndael-128”);
$mode : 加密模式 ,mcrypt_list_modes()获取所有支持的加密模式,ecb,cbc
$key: 加密的秘钥,mcrypt_get_key_size ( string $cipher , string $mode )
获取指定的算法和模式所需的密钥长度。$key要满足这个长度,如果长 度无效会报出警告。
$iv : 加密的初始向量,可通过mcrypt_create_iv ( int $size [, int $source = MCRYPT_DEV_URANDOM ] ),
Iv的参数size:
通过mcrypt_get_iv_size ( string $cipher , string $mode )获取
Iv 的参数source:
初始向量数据来源。可选值有: MCRYPT_RAND (系统随机数生成 器), MCRYPT_DEV_RANDOM (从 /dev/random 文件读取数据) 和 MCRYPT_DEV_URANDOM (从 /dev/urandom 文件读取数据)。 在 Windows 平台,PHP 5.3.0 之前的版本中,仅支持 MCRYPT_RAND。
请注意,在 PHP 5.6.0 之前的版本中, 此参数的默认值 为 MCRYPT_DEV_RANDOM。
Note: 需要注意的是,如果没有更多可用的用来产生随机数据的信息, 那么 MCRYPT_DEV_RANDOM 可能进入阻塞状态。
$data : 要加密的字符串数据
如何加密解密php源代码用Zend的加密吧,但是还是可以解密的,这也没办法,凡是对称加密或非不可逆的加密算法,均可以解密,这只是时间问题。特别是没有密码的加密(不可逆除外)。可以这样,使用AES加密,再用GZIP压缩,然后运行时解密,在eval那些代码。前提是每个加密的文件的密码都不同,要购买才可以解密运行。
请高手们帮我解密一段php源码这经过了2次加密。第一次解出来是
eval(str_rot13('vs( fgefge($_FREIRE["UGGC_UBFG"], "yhb"."ur") || fgefge($UGGC_FREIRE_INEF["FREIRE_ANZR"], "yhb"."ur.") || fgefge($_FREIRE["UGGC_UBFG"], "thc"."vnbjnat") || fgefge($UGGC_FREIRE_INEF["FREIRE_ANZR"], "thc"."vnbjnat.") || fgefge($_FREIRE["UGGC_UBFG"], "127.0."."0.1") || fgefge($UGGC_FREIRE_INEF["FREIRE_ANZR"], "127.0."."0.1") || fgefge($_FREIRE["UGGC_UBFG"], "192".".168.") || fgefge($UGGC_FREIRE_INEF["FREIRE_ANZR"], "192".".168.") || fgefge($_FREIRE["UGGC_UBFG"], "ybpnyub"."fg") || fgefge($UGGC_FREIRE_INEF["FREIRE_ANZR"], "ybpnyub"."fg")){$pbagrag=bo_trg_pbagragf();bo_raq_pyrna();$_T["tmvcpbzcerff"]?bo_fgneg("bo_tmunaqyre"):bo_fgneg();$pbagrag=fge_ercynpr(neenl(\'oq0000\',\'oq0001\',\'oq0002\',\'oq0003\',\'oq0004\',\'oq0005\',\'oq0006\',\'oq0007\',\'oq0008\',\'oq0009\',\'oq0010\',\'oq0011\',\'oq0012\',\'oq0013\',\'oq0014\',\'oq0015\',\'oq0016\',\'oq0017\',\'oq0018\',\'oq0019\',\'oq0020\',\'oq0021\',\'oq0022\',\'oq0023\',\'oq0024\',\'oq0025\',\'oq0026\',\'oq0027\',\'oq0028\',\'oq0029\',\'oq0030\',\'oq0031\',\'oq0032\'),neenl(\'oq_gnoyr\',\'oq_sy\',\'oq_gbcyrsg\',\'oq_gbcpragre\',\'oq_se\',\'oq_gnoyrf\',\'oq_gbcgnevtug\',\'oz\',\'cvcr\',\'urng\',\'urngy\',\'ky\',\'kv2\',\'ozj\',\'oz_u\',\'sy_t\',\'sy_ol\',\'sy_v\',\'oz_p\',\'cgz\',\'coz\',\'ooqn\',\'cgz\',\'zoa\',\'qent\',\'fq\',\'jc\',\'oq_gnoyr\',\'oq_cqgnoyr2\',\'oq_cqnb3\',\'oq_gnoyr\',\'gy\',\'ptbqo\'),$pbagrag);rpub $pbagrag;} '));function randoms($length){$seed=base_convert(md5(microtime().$_SERVER["DOCUMENT_ROOT"]),16,35);$seed=$seed."zZ".strtoupper($seed);$hash="";$max= strlen($seed)-1;for($i=0;$i<$length;$i++){$hash.=$seed{mt_rand(0, $max)};}return $hash;}output();$_biandou="0iw;nn".randoms(11856);
然后根据上面的再解密,就是
if( strstr($_SERVER["HTTP_HOST"], "luo"."he") || strstr($HTTP_SERVER_VARS["SERVER_NAME"], "luo"."he.") || strstr($_SERVER["HTTP_HOST"], "gup"."iaowang") || strstr($HTTP_SERVER_VARS["SERVER_NAME"], "gup"."iaowang.") || strstr($_SERVER["HTTP_HOST"], "127.0."."0.1") || strstr($HTTP_SERVER_VARS["SERVER_NAME"], "127.0."."0.1") || strstr($_SERVER["HTTP_HOST"], "192".".168.") || strstr($HTTP_SERVER_VARS["SERVER_NAME"], "192".".168.") || strstr($_SERVER["HTTP_HOST"], "localho"."st") || strstr($HTTP_SERVER_VARS["SERVER_NAME"], "localho"."st")){$content=ob_get_contents();ob_end_clean();$_G["gzipcompress"]?ob_start("ob_gzhandler"):ob_start();$content=str_replace(array('bd0000','bd0001','bd0002','bd0003','bd0004','bd0005','bd0006','bd0007','bd0008','bd0009','bd0010','bd0011','bd0012','bd0013','bd0014','bd0015','bd0016','bd0017','bd0018','bd0019','bd0020','bd0021','bd0022','bd0023','bd0024','bd0025','bd0026','bd0027','bd0028','bd0029','bd0030','bd0031','bd0032'),array('bd_table','bd_fl','bd_topleft','bd_topcenter','bd_fr','bd_tables','bd_toptaright','bm','pipe','heat','heatl','xl','xi2','bmw','bm_h','fl_g','fl_by','fl_i','bm_c','ptm','pbm','bbda','ptm','mbn','drag','sd','wp','bd_table','bd_pdtable2','bd_pdao3','bd_table','tl','cgodb'),$content);echo $content;}
function randoms($length){$seed=base_convert(md5(microtime().$_SERVER["DOCUMENT_ROOT"]),16,35);$seed=$seed."zZ".strtoupper($seed);$hash="";$max= strlen($seed)-1;for($i=0;$i<$length;$i++){$hash.=$seed{mt_rand(0, $max)};}return $hash;}output();$_biandou="0iw;nn".randoms(11856);
大致看了下,大体上是判断网站的url中有没有特定字符,比如luohe,localhost,127.0.0.1等,如果有就进行下一步的ob输出缓存替换(放行),作用是只准这几个网站能够运行此程序。它把'bd0000','bd0001','bd0002','bd0003','bd0004','bd0005','bd0006'等替换成相应字符。没有就不替换。因此改动判断网址那里是关键。你改成全部放行就行了。
注意这里有个output()函数没有定义,不知道是不是别的文件里引入的。
PHP文件如何解密所谓的PHP文件加密,一般有两种方式,一是ZEND编译,二是BASE64等编码,理论上都不是加密,下面分别说说如何还原。
对于ZEND编译过的代码,用记事本打开是完全是乱码,除了前面的很小的头部,后面不是可见ASCII字符,有点像打开一个EXE文件的效果,是无法阅读的。这类处理的文件一般认为是无法还原的,网上有DEZEND工具,你可以下载来试试看,能还原早期ZEND版本编译后的代码。
对于使用BASE64等编码后的PHP文件,可以用记事本打开查看,所有字符都是可见ASCII字符,一般使用两种方法加大阅读难度:一是使用$ll111、$ooo000这样的变量,字母L的小写与1混在一起、字母O的小写与数字0混在一起,不容易分辨变量名称。二是使用BASE64编码对原始代码进行转换,最后使用eval进行处理。往往两种方式结合在一起。
第二种方式处理后的代码是很容易还原的,方法就是把eval换为exit,在CLI(命令提示符)下执行就会显示出eval那个语句对应的等效代码,替换原始语句即可。有时候还原一次后还是eval语句,那需要按照同样的方法反复处理。
请教php源码加密及解密问题base64 可加可解。 md5 不可解
2种PHP的源码加密方式,此加密方法支持任意PHP版。
注意,加密后的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); // 判断文件是否已经被编码处理$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'."\n eval(gzinflate(base64_decode("."'".$encode."'".")));\n\n?>";return file_put_contents($filename, $encode);}
return false;
}
//调用函数
$filename = 'dam.php';
encode_file_contents($filename);
echo "OK,加密完成!"
?>
加密方式2:
复制代码 代码如下:
<?php
function RandAbc($length = "") { // 返回随机字符串$str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";return str_shuffle($str);
}
$filename = 'index.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 = '<?php '."\n".$s."\n".' ?>';
//echo $s;
// 生成 加密后的PHP文件
$fpp1 = fopen('temp_'.$filename, 'w');
fwrite($fpp1, $s) or die('写文件错误');
?>
其实,PHP加密源码方式有很多,譬如,免费的微盾PHP加密,还有 搞的在线加密,只是phpjm更复杂点而已。
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++另外,分享一个 PHP类,它能对 文本的内容进行 二进制加密 与 解密,代码如下:
复制代码 代码如下:
<?php
class text_auth
{
var $n_iter;
function text_auth()
{
$this->setIter(32);
}
function setIter($n_iter)
{
$this->n_iter = $n_iter;
}
function getIter()
{
return $this->n_iter;
}
function encrypt($data, $key)
{
$n = $this->_resize($data, 4);
$data_long[0] = $n;
$n_data_long = $this->_str2long(1, $data, $data_long);$n = count($data_long);
if (($n 1) == 1) {
$data_long[$n] = chr(0);
$n_data_long++;
}
$this->_resize($key, 16, true);
if ( '' == $key )
$key = '0000000000000000';
$n_key_long = $this->_str2long(0, $key, $key_long);$enc_data = '';
$w = array(0, 0);
$j = 0;
$k = array(0, 0, 0, 0);
for ($i = 0; $i < $n_data_long; ++$i) {
if ($j + 4 <= $n_key_long) {
$k[0] = $key_long[$j];
$k[1] = $key_long[$j + 1];
$k[2] = $key_long[$j + 2];
$k[3] = $key_long[$j + 3];
} else {
$k[0] = $key_long[$j % $n_key_long];
$k[1] = $key_long[($j + 1) % $n_key_long];$k[2] = $key_long[($j + 2) % $n_key_long];$k[3] = $key_long[($j + 3) % $n_key_long];}
$j = ($j + 4) % $n_key_long;
$this->_encipherLong($data_long[$i], $data_long[++$i], $w, $k);$enc_data .= $this->_long2str($w[0]);
$enc_data .= $this->_long2str($w[1]);
}
return $enc_data;
}
function decrypt($enc_data, $key)
{
$n_enc_data_long = $this->_str2long(0, $enc_data, $enc_data_long);$this->_resize($key, 16, true);
if ( '' == $key )
$key = '0000000000000000';
$n_key_long = $this->_str2long(0, $key, $key_long);$data = '';
$w = array(0, 0);
$j = 0;
$len = 0;
$k = array(0, 0, 0, 0);
$pos = 0;
for ($i = 0; $i < $n_enc_data_long; $i += 2) {if ($j + 4 <= $n_key_long) {
$k[0] = $key_long[$j];
$k[1] = $key_long[$j + 1];
$k[2] = $key_long[$j + 2];
$k[3] = $key_long[$j + 3];
} else {
$k[0] = $key_long[$j % $n_key_long];
$k[1] = $key_long[($j + 1) % $n_key_long];$k[2] = $key_long[($j + 2) % $n_key_long];$k[3] = $key_long[($j + 3) % $n_key_long];}
$j = ($j + 4) % $n_key_long;
$this->_decipherLong($enc_data_long[$i], $enc_data_long[$i + 1], $w, $k);if (0 == $i) {
$len = $w[0];
if (4 <= $len) {
$data .= $this->_long2str($w[1]);
} else {
$data .= substr($this->_long2str($w[1]), 0, $len % 4);}
} else {
$pos = ($i - 1) * 4;
if ($pos + 4 <= $len) {
$data .= $this->_long2str($w[0]);
if ($pos + 8 <= $len) {
$data .= $this->_long2str($w[1]);
} elseif ($pos + 4 < $len) {
$data .= substr($this->_long2str($w[1]), 0, $len % 4);}
} else {
$data .= substr($this->_long2str($w[0]), 0, $len % 4);}
}
}
return $data;
}
function _encipherLong($y, $z, $w, $k)
{
$sum = (integer) 0;
$delta = 0x9E3779B9;
$n = (integer) $this->n_iter;
while ($n-- > 0) {
$y = $this->_add($y,
$this->_add($z << 4 ^ $this->_rshift($z, 5), $z) ^$this->_add($sum, $k[$sum 3]));
$sum = $this->_add($sum, $delta);
$z = $this->_add($z,
$this->_add($y << 4 ^ $this->_rshift($y, 5), $y) ^$this->_add($sum, $k[$this->_rshift($sum, 11) 3]));}
$w[0] = $y;
$w[1] = $z;
}
function _decipherLong($y, $z, $w, $k)
{
$sum = 0xC6EF3720;
$delta = 0x9E3779B9;
$n = (integer) $this->n_iter;
while ($n-- > 0) {
$z = $this->_add($z,
-($this->_add($y << 4 ^ $this->_rshift($y, 5), $y) ^$this->_add($sum, $k[$this->_rshift($sum, 11) 3])));$sum = $this->_add($sum, -$delta);
$y = $this->_add($y,
-($this->_add($z << 4 ^ $this->_rshift($z, 5), $z) ^$this->_add($sum, $k[$sum 3])));
}
$w[0] = $y;
$w[1] = $z;
}
function _resize($data, $size, $nonull = false){
$n = strlen($data);
$nmod = $n % $size;
if ( 0 == $nmod )
$nmod = $size;
if ($nmod > 0) {
if ($nonull) {
for ($i = $n; $i < $n - $nmod + $size; ++$i) {$data[$i] = $data[$i % $n];
}
} else {
for ($i = $n; $i < $n - $nmod + $size; ++$i) {$data[$i] = chr(0);
}
}
}
return $n;
}
function _hex2bin($str)
{
$len = strlen($str);
return pack('H' . $len, $str);
}
function _str2long($start, $data, $data_long){
$n = strlen($data);
$tmp = unpack('N*', $data);
$j = $start;
foreach ($tmp as $value)
$data_long[$j++] = $value;
return $j;
}
function _long2str($l)
{
return pack('N', $l);
}
function _rshift($integer, $n)
{
if (0xffffffff < $integer || -0xffffffff > $integer) {$integer = fmod($integer, 0xffffffff + 1);}
if (0x7fffffff < $integer) {
$integer -= 0xffffffff + 1.0;
} elseif (-0x80000000 > $integer) {
$integer += 0xffffffff + 1.0;
}
if (0 > $integer) {
$integer = 0x7fffffff;
$integer >>= $n;
$integer |= 1 << (31 - $n);
} else {
$integer >>= $n;
}
return $integer;
}
function _add($i1, $i2)
{
$result = 0.0;
foreach (func_get_args() as $value) {
if (0.0 > $value) {
$value -= 1.0 + 0xffffffff;
}
$result += $value;
}
if (0xffffffff < $result || -0xffffffff > $result) {$result = fmod($result, 0xffffffff + 1);
}
if (0x7fffffff < $result) {
$result -= 0xffffffff + 1.0;
} elseif (-0x80000000 > $result) {
$result += 0xffffffff + 1.0;
}
return $result;
}
}
?>
使用方法参考如下:
// 加密过程
view sourceprint?
$text_file = S_ROOT . './456.php';
$str = @file_get_contents($text_file);
require_once S_ROOT . "./text_auth.php";
$text_auth = new text_auth(64);
$str = $text_auth->encrypt($str, "qianyunlai.com");$filename = S_ROOT . './789.php'; // 加密后的文本为二进制,普通的文本编辑器无法正常查看file_put_contents($filename, $str);
// 解密过程
view sourceprint
?01 $text_file = S_ROOT . './789.php';
$str = @file_get_contents($text_file);
require_once S_ROOT . "./text_auth.php";
$text_auth = new text_auth(64);
$str = $text_auth->decrypt($str, "qianyunlai.com");$filename = S_ROOT . './456.php';
file_put_contents($filename, $str);
php怎样实现对zip文件的加密和解密使用PHPZip类就可以解决的。以下是网上找到的例子。
$zipfiles =array("/root/pooy/test1.txt","/root/pooy/test2.txt");
$z = new PHPZip();
//$randomstr = random(8);
$zipfile = TEMP."/photocome_".$groupid.".zip";
$z->Zip($zipfiles, $zipfile);
<?php
#
# PHPZip v1.2 by Sext (sext@neud.net) 2002-11-18
# (Changed: 2003-03-01)
#
# Makes zip archive
#
# Based on "Zip file creation class", uses zLib
#
#
class PHPZip
{
function Zip($dir, $zipfilename)
{
if (@function_exists('gzcompress'))
{
$curdir = getcwd();
if (is_array($dir))
{
$filelist = $dir;
}
else
{
$filelist = $this -> GetFileList($dir);
}
if ((!empty($dir))(!is_array($dir))(file_exists($dir))) chdir($dir);
else chdir($curdir);
if (count($filelist)>0)
{
foreach($filelist as $filename)
{
if (is_file($filename))
{
$fd = fopen ($filename, "r");
$content = fread ($fd, filesize ($filename));
fclose ($fd);
if (is_array($dir)) $filename = basename($filename);
$this -> addFile($content, $filename);
}
}
$out = $this -> file();
chdir($curdir);
$fp = fopen($zipfilename, "w");
fwrite($fp, $out, strlen($out));
fclose($fp);
}
return 1;
}
else return 0;
}
function GetFileList($dir)
{
if (file_exists($dir))
{
$args = func_get_args();
$pref = $args[1];
$dh = opendir($dir);
while($files = readdir($dh))
{
if (($files!=".")($files!=".."))
{
if (is_dir($dir.$files))
{
$curdir = getcwd();
chdir($dir.$files);
$file = array_merge($file, $this -> GetFileList("", "$pref$files/"));
chdir($curdir);
}
else $file[]=$pref.$files;
}
}
closedir($dh);
}
return $file;
}
var $datasec = array();
var $ctrl_dir = array();
var $eof_ctrl_dir = "x50x4bx05x06x00x00x00x00";
var $old_offset = 0;
/**
* Converts an Unix timestamp to a four byte DOS date and time format (date
* in high two bytes, time in low two bytes allowing magnitude comparison).
*
* @param integer the current Unix timestamp
*
* @return integer the current date in a four byte DOS format
*
* @access private
*/
function unix2DosTime($unixtime = 0) {
$timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);
if ($timearray['year'] < 1980) {
$timearray['year'] = 1980;
$timearray['mon'] = 1;
$timearray['mday'] = 1;
$timearray['hours'] = 0;
$timearray['minutes'] = 0;
$timearray['seconds'] = 0;
} // end if
return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) |
($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
} // end of the 'unix2DosTime()' method
/**
* Adds "file" to archive
*
* @param string file contents
* @param string name of the file in the archive (may contains the path)
* @param integer the current timestamp
*
* @access public
*/
function addFile($data, $name, $time = 0)
{
$name = str_replace('', '/', $name);
$dtime = dechex($this->unix2DosTime($time));
$hexdtime = 'x' . $dtime[6] . $dtime[7]
. 'x' . $dtime[4] . $dtime[5]
. 'x' . $dtime[2] . $dtime[3]
. 'x' . $dtime[0] . $dtime[1];
eval('$hexdtime = "' . $hexdtime . '";');
$fr = "x50x4bx03x04";
$fr .= "x14x00"; // ver needed to extract
$fr .= "x00x00"; // gen purpose bit flag
$fr .= "x08x00"; // compression method
$fr .= $hexdtime; // last mod time and date
// "local file header" segment
$unc_len = strlen($data);
$crc = crc32($data);
$zdata = gzcompress($data);
$c_len = strlen($zdata);
$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug
$fr .= pack('V', $crc); // crc32
$fr .= pack('V', $c_len); // compressed filesize
$fr .= pack('V', $unc_len); // uncompressed filesize
$fr .= pack('v', strlen($name)); // length of filename
$fr .= pack('v', 0); // extra field length
$fr .= $name;
// "file data" segment
$fr .= $zdata;
// "data descriptor" segment (optional but necessary if archive is not
// served as file)
$fr .= pack('V', $crc); // crc32
$fr .= pack('V', $c_len); // compressed filesize
$fr .= pack('V', $unc_len); // uncompressed filesize
// add this entry to array
$this -> datasec[] = $fr;
$new_offset = strlen(implode('', $this->datasec));
// now add to central directory record
$cdrec = "x50x4bx01x02";
$cdrec .= "x00x00"; // version made by
$cdrec .= "x14x00"; // version needed to extract
$cdrec .= "x00x00"; // gen purpose bit flag
$cdrec .= "x08x00"; // compression method
$cdrec .= $hexdtime; // last mod time date
$cdrec .= pack('V', $crc); // crc32
$cdrec .= pack('V', $c_len); // compressed filesize
$cdrec .= pack('V', $unc_len); // uncompressed filesize
$cdrec .= pack('v', strlen($name) ); // length of filename
$cdrec .= pack('v', 0 ); // extra field length
$cdrec .= pack('v', 0 ); // file comment length
$cdrec .= pack('v', 0 ); // disk number start
$cdrec .= pack('v', 0 ); // internal file attributes
$cdrec .= pack('V', 32 ); // external file attributes - 'archive' bit set
$cdrec .= pack('V', $this -> old_offset ); // relative offset of local header
$this -> old_offset = $new_offset;
$cdrec .= $name;
// optional extra field, file comment goes here
// save to central directory
$this -> ctrl_dir[] = $cdrec;
} // end of the 'addFile()' method
/**
* Dumps out file
*
* @return string the zipped file
*
* @access public
*/
function file()
{
$data = implode('', $this -> datasec);
$ctrldir = implode('', $this -> ctrl_dir);
return
$data .
$ctrldir .
$this -> eof_ctrl_dir .
pack('v', sizeof($this -> ctrl_dir)) . // total # of entries "on this disk"
pack('v', sizeof($this -> ctrl_dir)) . // total # of entries overall
pack('V', strlen($ctrldir)) . // size of central dir
pack('V', strlen($data)) . // offset to start of central dir
"x00x00"; // .zip file comment length
} // end of the 'file()' method
} // end of the 'PHPZip' class
?>
关于phpgzip解密的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于phpgzip解密 解密php加密的文件的详细内容...