這篇文章主要介紹了關於PHP源碼php-beast加密,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下
安裝php-beast
php-beast源碼下載地址:
https://github.com/liexusong/php-beast
解壓,並進入源碼目錄
[innpay@localhost soft]$ unzip php-beast-master.zip [innpay@localhost soft]$ cd php-beast-master[innpay@localhost php-beast-master]$ pwd/home/pony/soft/php-beast-master
編譯,安裝
[innpay@localhost php-beast-master]$ /home/pony/php/bin/phpize Configuring for:PHP Api Version: 20131106Zend Module Api No: 20131226Zend Extension Api No: 220131226[innpay@localhost php-beast-master]$ ./configure --with-php-config=/home/pony/php/bin/php-config[innpay@localhost php-beast-master]$ make[innpay@localhost php-beast-master]$ make installInstalling shared extensions: /home/pony/php/lib/php/extensions/no-debug-non-zts-20131226/
安裝完成後,產生beast.so在no-debug-non-zts-20131226這個目錄下。
編輯php.ini,加入配置項: extension=beast.so
重啟apache,通過phpinfo查看beast是否生效
[innpay@localhost apache2]$ ./bin/apachectl restart
使用php-beast
安裝完成後, 進入源碼目錄下的tools目錄,配置configure.ini
[innpay@localhost tools]$ cat configure.ini ; source pathsrc_path = "/home/pony/php/apache2/htdocs/wechat_nofity"; destination pathdst_path = "/home/pony/php/apache2/htdocs/des"; expire timeexpire = "2019-01-01 12:00:00"; encrypt typeencrypt_type = "DES"
src_path 是要加密項目的路徑,dst_path 是儲存加密後項目的路徑,expire 是設定項目可使用的時間 (expire 的格式是:YYYY-mm-dd HH:ii:ss)。encrypt_type是加密的方式,選擇項有:DES、AES、BASE64。 修改完 configure.ini 檔案後就可以使用命令 php encode_files.php 開始加密項目。
這裡可能遇到執行php命令無法識別的問題:
php: command not found
解決方案是把php的執行路徑加入.bash_profile環境變數的PATH中
執行加密操作:
[innpay@localhost tools]$ php encode_files.phpSource code path: /home/pony/php/apache2/htdocs/wechat_nofityDestination code path: /home/pony/php/apache2/htdocs/desExpire time: 2019-01-01 12:00:00------------- start process -------------PHP Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/pony/php/soft/php-beast-master/tools/encode_files.php on line 147Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/pony/php/soft/php-beast-master/tools/encode_files.php on line 147Processed encrypt files [64%] - 100%Failed to encode file `/home/pony/php/apache2/htdocs/wechat_nofity/wechat.class.php'Processed encrypt files [100%] - 100%Finish processed encrypt files, used 0.699295 seconds
這裡提示我有一個名為wechat.class.php的檔案加密失敗,我懷疑是檔案太長導致的,沒關係有一個不成功我就單獨拷貝過去。
加密後的目錄是des目錄,進去看下源碼檔案,確實都是亂碼。但是訪問所有的php頁面都是正常的。
修改預設加密key
因為我這裡用的是des加密方法,肯定會用到一個des密鑰,預設的密鑰在php-beast目錄下的des_algo_handler.c檔案裡:
#include <stdlib.h>#include <string.h>#include "beast_module.h"#include "des_algo_lib.c"static char key[8] = { 0x01, 0x1f, 0x01, 0x1f, 0x01, 0x0e, 0x01, 0x0e,};
可以直接改,改完重新編譯即可。
以上就是本文的全部內容,希望對大家的學習有所協助,更多相關內容請關注topic.alibabacloud.com!