phpzip加密,phpdes加密

本文目錄一覽:

zip密碼 php

用PHP的zip模塊進行壓縮加密.

開始

$zipArc = new \ZipArchive();if ($zipArc-open(‘/home/test.zip’, ZipArchive::CREATE | ZipArchive::OVERWRITE) === true) {    //設置密碼 注意此處不是加密,僅僅是設置密碼

   if (!$zipArc-setPassword(‘password’)) {        throw new RuntimeException(‘Set password failed’);

   }    //往壓縮包內添加文件

   $zipArc-addFile(‘/home/test.png’, ‘1/test.png’);    //加密文件 此處文件名及路徑是壓縮包內的

   if (!$zipArc-setEncryptionName(‘1/test.png’, ZipArchive::EM_AES_256)) {        throw new RuntimeException(‘Set encryption failed’);

   }

}

$zipArc-close();

注意事項

1 PHP7.2以下不支持加密

php7.2 以下是不支持加密的,我們看一下php官方文檔中的解釋

從PHP 7.2.0和libzip 1.2.0開始,密碼用於解壓縮歸檔,也是ZipArchive :: setEncryptionName() 和ZipArchive :: setEncryptionIndex()的默認密碼。

以前,此功能僅設置用於解壓縮存檔的密碼; 它沒有將非密碼保護的ZipArchive 變成受密碼保護的ZipArchive。

也就是說php7.2之前,setPassword(‘password’)這個方法僅僅是設置setEncryptionName()和setEncryptionIndex()的默認密碼,卻沒有進行加密操作!!!,就問你坑不坑!!

2 方法找不到

提示沒有setEncryptionName和setEncryptionIndex方法時,請編譯時zip模塊時用以下參數

–with-libzip

–enable-zip

3 目錄結構問題

待壓縮的文件目錄,比說說是/home/test/a.png

壓縮後,你發現壓縮包內的目錄結構是/home/test/a.png,

也就是說壓縮包原封不動的保持了原來文件的目錄.可是我們想自定義壓縮包目錄怎麼辦呢?

$a = ‘/home/test.png’;

$b = ‘1/test.png’;//$a是待添加的文件路徑  $b是壓縮包內的路徑$zipArc-addFile($a, $b);

php 怎麼用zend加密

可以加密就可以解密。

解密ZEND加密後的PHP文件:

zend加密php文件解密工具Dezender可以做到。

1、下載Dezender.zip

2、解壓到盤裡面,最好不要有中文路徑,比如解壓到 I:\Dezender 裡面,修改 I:\Dezender\PHP5\PHP5\php.ini文件,修改裡面的文件路徑。

3、打開cmd命令行

然後就可以看見文件目錄下面會多出一個文件    文件名.de.php

4、進入I:\Dezender 目錄下面的

5、寫一個批處理文件,可以直接把一個目錄下面的文件全部批量解密

PHP-php生成zip壓縮文件如何給該文件加解壓縮密碼

?php

//需開啟配置 php_zip.dll

//phpinfo();

header(“Content-type:text/html;charset=utf-8”);

function get_zip_originalsize($filename, $path) {

 //先判斷待解壓的文件是否存在

 if(!file_exists($filename)){

  die(“文件 $filename 不存在!”);

 } 

 $starttime = explode(‘ ‘,microtime()); //解壓開始的時間

 //將文件名和路徑轉成windows系統默認的gb2312編碼,否則將會讀取不到

 $filename = iconv(“utf-8″,”gb2312”,$filename);

 $path = iconv(“utf-8″,”gb2312”,$path);

 //打開壓縮包

 $resource = zip_open($filename);

 $i = 1;

 //遍歷讀取壓縮包裡面的一個個文件

 while ($dir_resource = zip_read($resource)) {

  //如果能打開則繼續

  if (zip_entry_open($resource,$dir_resource)) {

   //獲取當前項目的名稱,即壓縮包裡面當前對應的文件名

   $file_name = $path.zip_entry_name($dir_resource);

   //以最後一個“/”分割,再用字符串截取出路徑部分

   $file_path = substr($file_name,0,strrpos($file_name, “/”));

   //如果路徑不存在,則創建一個目錄,true表示可以創建多級目錄

   if(!is_dir($file_path)){

    mkdir($file_path,0777,true);

   }

   //如果不是目錄,則寫入文件

   if(!is_dir($file_name)){

    //讀取這個文件

    $file_size = zip_entry_filesize($dir_resource);

    //最大讀取6M,如果文件過大,跳過解壓,繼續下一個

    if($file_size(1024*1024*6)){

     $file_content = zip_entry_read($dir_resource,$file_size);

     file_put_contents($file_name,$file_content);

    }else{

     echo “p “.$i++.” 此文件已被跳過,原因:文件過大, – “.iconv(“gb2312″,”utf-8″,$file_name).” /p”;

    }

   }

   //關閉當前

   zip_entry_close($dir_resource);

  }

 }

 //關閉壓縮包

 zip_close($resource); 

 $endtime = explode(‘ ‘,microtime()); //解壓結束的時間

 $thistime = $endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]);

 $thistime = round($thistime,3); //保留3為小數

 echo “p解壓完畢!,本次解壓花費:$thistime 秒。/p”;

}

$size = get_zip_originalsize(‘20131101.zip’,’temp/’);

?

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

?

php如何生成自解壓文件?

php ZipArchive 能否在指定目錄生成壓縮包

初步接觸ZipArchive , 目前發現 ZipArchive類生成的zip壓縮包是存儲在 ppublic function backupfiles(){ $filename = “backups/”. time().”.zip”; $zip = new \ZipArchive(); $zip-open($filename,\ZipArchive::CREATE); $path = ‘demo’;//指定的目錄 $this-addFileToZip($path, $zip); } public function addFileT

如何用PHP創建一個加密的zip壓縮文件

/* creates a compressed zip file */function create_zip($files = array(),$destination = ”,$overwrite = false) { //if the zip file already exists and overwrite is false, return false if(file_exists($destination) 。

PHP-php生成zip壓縮文件如何給該文件加解壓縮密碼

php如何壓縮一個文件夾裡面所有的文件到zip文件裡面?

//函數:文件壓縮//壓縮參數:需要壓縮的文件或文件夾(文件可為數組),壓縮後的zip文件名及存放路徑,壓縮類型1:文件夾2:文件,後續操作1:壓縮後下載;2:存放在服務器上(默認為/@Upload下)//壓縮文件夾示例:Tozip(“./”,”../”.date(“d-H-i-s”).”.zip”,1

如何在PHP中創建壓縮的RAR文件

$filename = “./” . date ( ‘YmdH’ ) . “.zip”; // 最終生成的文件名(含路徑) // 生成文件 $zip = new ZipArchive (); // 使用本類,linux需開啟zlib,windows需取消php_zip.dll前的注釋 if ($zip-open ( $filename, ZIPARCHIVE::CREATE ) 。

看你的內存是多大了,只要你的虛擬內存和物理內存夠大。

怎樣用php壓縮解壓rar,zip文件?

要用PHP壓縮解壓文件,常用的方法是調用命令行去執行解壓縮操作 可以用exec() 、system()等函數調用shell命令 Linux下解壓縮命令是tar [-cxtzjvfpPN] 文件與目錄,tar命令可以壓縮解壓.tar、.gz、.tar.gz、.tgz、.bz

請高手指點:PHP 如何解壓縮zip格式壓縮的文件或壓zip格式壓縮了幾個文件,或壓縮了一個文件夾,文件夾里有多個文件, 現/** * PHP在線壓縮/解壓實例 */ date_default_timezone_set(‘prc’); $zip = new engine_compress_decompress(); if (isset($_POST)) { $sourcePath = ”; //默認位置 if (isset($_FILES[‘upfile’])) //上傳文件 { $stmp = $zip-fileUpload(‘upf

以上就是CSS布局HTML為大家整理的php生成zip壓縮文件的方法詳解 技術分享內容,如果覺得小編的資源對您有幫助 不要忘記分享給您身邊的朋友哦!

如何對PHP文件進行加密

Zend Guard是目前市面上最成熟的PHP源碼加密產品。

經過本人搜集資料,親身測試後,總結了如何利用Zend Guard對PHP文件進行加密,以及如何利用Zend Loader對加密後的PHP文件進行解密。

我使用的是Wampserver2.2,其中php的版本是5.3.10。(注意:這個裡面自帶的php版本屬於TS版本,即Thread safety線程安全)

Zend Guard的安裝及破解

點擊下載 Zend Guard5.5.0,下載完成後,請自行傻瓜式安裝。

破解需要注意以下幾點:

1、本KEY的有效時間為2010年7月10號,因此激活時,請將自己電腦的系統時間調整到這個時間之前,如:2009-01-01

2、本KEY激活的為試用版,加密過的文件只有14天有效時間,因此在加密文件時,請將自己電腦的系統時間向後調整幾年,如:2020-01-01

3、點擊下載授權文件 zend_guard授權文件.zip,解壓得到zend_guard.zl,即激活用的文件

4、打開Zend Guard 5.5.0,[Help] – [Register] – [Search for a license file on my disk],選擇zend_guard.zl授權文件激活即可

如何使用Zend Guard進行加密?

1、打開Zend Guard 5.5.0,[File]-[New]-[Zend Guard Project],新建項目。

彈出如下的對話框:

2、點擊 Next ,下一步。彈出如下對話框,選擇要進行加密的源文件或文件夾。

本步驟是選擇要加密的文件,可以是單個文件[Add File]或整個文件夾[Add Folder],然後[Next]。

(此處,我選擇的是對整個文件夾進行加密。即 D:\wamp\www\demo 里的所有文件進行加密。)

3、接下來是選擇PHP的版本[與你web服務器上PHP的版本相對照],這裡很重要,版本不對會出錯,[Finish]完成項目的創建。

注意: 對於Zend Guard 5.5.0這個版本的加密軟件,最高只可支持5.3版本的PHP。如果您的PHP版本較高,請到Zend Guard官網下載對應的高版本加密軟件。

(由於,我的PHP版本是PHP 5.3.10,故這裡我選擇PHP 5.3,其他地方可以默認,直接點擊完成)

4、在Zend Guard左側的Guard Explorer中,可以看到你新建的項目了,鼠標選中項目名稱後,右鍵單擊[Encode Project],完成。

如此,就實現了對PHP源碼的最簡單的加密。

我們可以在產品的輸出目錄(D:\productDir)里,看到加密後的文件。

可以看出,產品輸出目錄里的PHP文件已被加密了。

這種最簡單的加密方式,我們並沒有設置加密的有效期,也沒有設置許可證支持(即解密時,是否需要許可證文件),默認是永不過期,不需要解密許可文件。

如果要設置解密時的許可證文件,可以點擊 項目名稱(project_test) ,再點擊 項目主窗口中的 Overview 旁邊的 Security 選項卡,就可以進行更加安全的加密設置了。 如下圖:

Zend Loader 解密

上面我們已經對PHP代碼進行了最簡單的加密(編碼),加密後生成的PHP源代碼,就不能再被web服務器上的PHP模塊解析了。

當我們將加密後的php文件放到web服務器上執行時,會顯示如下信息:

Zend Guard Run-time support missing!

One more more files on this web site were encoded by ZendGuard and the required run-time support is not installed orproperly configured.

……

原來,加密後的php代碼需要ZendGuardLoader模塊才能正常運行。

因為我的php版本是5.3.10的,所以我這裡只提供了ZendGuardLoader-php-5.3-Windows,如果是其他版本的php,請自行百度。

點擊下載 ZendGuardLoader-php-5.3-Windows

下載後,解壓壓縮包,找到目錄里的 ZendLoader.dll 文件,將它複製到你的php目錄里的ext目錄(PHP的擴展庫目錄)下,再編輯PHP的配置文件php.ini,添加如下代碼:

[Zend.loader],

zend_loader.enable=1

zend_loader.disable_licensing=1

zend_loader.obfuscation_level_support=3

zend_loader.license_path=

zend_extension=”d:\wamp\bin\php\php5.3.10\ext\ZendLoader.dll”

註:

zend_loader.enable 表示是否啟用zend loader,1表示啟用,0表示禁用

zend_loader.disable_licensing 表示是否禁用許可證,1表示禁用,0表示不禁用 (由於上面我加密php文件的時候,沒有設置許可證支持,故解密時,禁用許可證)

zend_loader.obfuscation_level_support 表示代碼混淆級別

zend_loader.license_path 指定許可證文件的路徑

zend_extension 指定zend loader 擴展文件 的路徑

配置完成後,重啟wampserver,如果您的php的版本是NTS(非線程安全的話),就可以正常執行加密後的PHP文件了。

但是,多數情況下的php版本都是TS(線程安全)的,比如,我這個wampserver集成環境中的php是php-5.3.10-ts,它是沒有辦法支持Zend Guard Loader擴展文件的。故還會報出上面的錯誤提示信息。

因為,Zend Guard Loader 只能支持 NTS版本的php,終極解決辦法是下載安裝 NTS 版本的php。

為了實現PHP源文件的 Zend 解密測試,可以下載安裝 php-5.3.29-nts-Win32-VC9-x86,再來配置 Zend Loader 擴展支持。

如何查看安裝好的PHP的版本及PHP是否已經成功支持Zend Loader?

通過查看 phpinfo() 函數的輸出信息,利用 Ctrl + F 快速查找關鍵字Thread Safety 和 Zend Guard Loader。

如本人安裝好php-5.3.29-nts版本的php後,phpinfo()的輸出信息如下:

可以看到,Thread Safety 對應的值為disabled,就說明該php的版本是 NTS (非線程安全)的,否則就是TS版本的。

輸出信息中,還可以看到 Zend Guard Loader v3.3 字樣,說明 Zend Guard Loader 也安裝成功了。

再往下面看,還可以查看 Zend Guard Loader 的配置信息,如下:

到此,整個 Zend Guard 加密和 Zend Guard Loader 解密,就介紹完畢了。

溫馨提示: 為了順利實現PHP代碼的zend加密和解密,建議使用PHP官網上主流的PHP的NTS版和Zend官網上對應的Zend Guard加密軟件、 Zend Guard Loader解密插件。

相關附件:

Wampserver2.2

Zend

Guard5.5.0

php-5.3.29-nts-Win32-VC9-x86

mod_fcgid-2.3.6-win32-x86.zip

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/154937.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-11-17 02:37
下一篇 2024-11-17 02:37

相關推薦

發表回復

登錄後才能評論