使用php screw進行原始碼加密
網址
http://sourceforge.net/projects/php-screw/
我的安裝環境
系統:Slackware 10
軟體:Apache 1.3.31
PHP 4.3.7
以上環境全部是slackware 10預設安裝後內建的。具體的Apache+php+mysql安裝方法參照如下
支援php的Apache環境安裝
獲得軟體
下載php_screw-1.3 (http://prdownloads.sourceforge.net/php-screw/php_screw-1.3.tgz?download)
安裝
1.將獲得的php_screw-1.3.tgz檔案放到/usr/local目錄下,然後用tar解壓縮
tar zxvf php_screw-1.3.tgz
2.進入/usr/local/php_screw-1.3目錄開始安裝
1cd /usr/local/php_screw-1.3
2phpize
3./configure
3.設定自己用來加密的密碼
vi my_screw.h
-- Please change the encryption SEED key (pm9screw_mycryptkey) into the
values according to what you like.
The encryption will be harder to break, if you add more values to the
encryption SEED array. However, the size of the SEED is unrelated to
the time of the decrypt processing.
* If you can read and understand the source code, to modify an original
encryption logic will be possible. But in general, this should not
be necessary.
OPTIONAL: Encrypted scripts get a stamp added to the beginning of the
file. If you like, you may change this stamp defined by
PM9SCREW and PM9SCREW_LEN in php_screw.h. PM9SCREW_LEN must
be less than or equal to the size of PM9SCREW.
4.編譯
make
5.拷貝modules目錄下的php_screw.so檔案到/usr/lib/php/extension目錄下
cp modules/php_screw.so /usr/lib/php/extension/
6.編輯php.ini檔案
在php.ini檔案裡,加入如下語句
extension=php_screw.so
7.重新啟動Apache
/etc/rc.d/rc.httpd restart
8.編譯加密工具
cd tools
make
9.將tools目錄下加密用的工具screw拷貝到適當目錄
cp screw /usr/bin/
經過以上的10步,就已經把php_screw-1.3全部安裝完成了。並且現在的php也已經支援解釋加密過的php檔案了
使用
1.現寫一個要加密的php檔案。
我寫了如下的一個用來測試php速度的compute.php檔案
0102$a=0;
03$t=time();
04for($i=0;$i<5000000;$i++)
05{$a=$a*$i;}
06$t1=time();
07echo "
";
08echo "It used:";
09echo $t1-$t;
10echo "seconds";
11?>
將上面的compute.php檔案放到/var/www/htdocs目錄下。通過瀏覽器訪問,將顯示出php在大量計算時的速度(只能粗數量級估計一下)
2.將我們寫的php檔案加密
cd /var/www/htdocs/
screw compute.php
我們加密後,現在目錄下的compute.php檔案就是我們已經加密的了。而源檔案被改名為compute.php.screw存放了。
我們現在再測試一下compute.php,看看能否正常使用?速度如何?
我比較了一下,加密前後的速度大概一樣,基本沒有太多的損失。