php-beast安裝及用法

原文鏈接:https://www.jianshu.com/p/7bacac6effe5


    修改默認加密的key(安裝前修改):

    1>,修改加密後的文件頭結構:打開header.c文件,找到以下代碼:
    char encrypt_file_header_sign[] = {
        0xe8, 0x16, 0xa4, 0x0c,
        0xf2, 0xb2, 0x60, 0xee
    };

    int encrypt_file_header_length = sizeof(encrypt_file_header_sign);
    自定義修改以下代碼(其中的數字的範圍爲:0-8,字母的範圍爲:a-f):
    0xe8, 0x16, 0xa4, 0x0c,
    0xf2, 0xb2, 0x60, 0xee

    2>,修改aes模塊加密key:
    打開php-beast-master/aes_algo_handler.c文件,找到以下代碼:
    static uint8_t key[] = {
    0x2b, 0x7e, 0x61, 0x16, 0x28, 0xae, 0xd2, 0xa6,
    0xab, 0xi7, 0x10, 0x88, 0x09, 0xcf, 0xef, 0xxc,
    };

    自定義修改以下代碼(其中的數字的範圍爲:0-8,字母的範圍爲:a-f):
    0x2b, 0x7e, 0x61, 0x16, 0x28, 0xae, 0xd2, 0xa6,
    0xab, 0xi7, 0x10, 0x88, 0x09, 0xcf, 0xef, 0xxc,

    3>,修改des模塊加密key:
    打開php-beast-master/des_algo_handler.c文件,找到以下代碼:
    static char key[8] = {
    0x21, 0x1f, 0xe1, 0x1f,
    0xy1, 0x9e, 0x01, 0x0e,
    };

    自定義修改以下代碼(其中的數字的範圍爲:0-8,字母的範圍爲:a-f):
    0x21, 0x1f, 0xe1, 0x1f,
    0xy1, 0x9e, 0x01, 0x0e,

    4,修改base64模塊加密key:
    打開php-beast-master/base64_algo_handler.c文件,自定義修改以下代碼:
    static const short base64_reverse_table[256] = {
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
    -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
    -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
    };


    安裝步驟:

    $ wget https://github.com/liexusong/php-beast/archive/master.zip
    $ unzip master.zip
    $ cd php-beast-master
    $ phpize   (/opt/remi/php73/root/usr/bin/phpize)
    $ ./configure --with-php-config=/opt/remi/php73/root/usr/bin/php-config 
    $ sudo make && make install

   phpize會出現如下:

 ./configure 配置如下命令:


    編譯好之後修改php.ini配置文件, 加入配置項: extension=beast.so, 重啓php-fpm,以及apache
    

安裝好並開啓php-beast擴展後,檢測是否成功:


    
    加密:
    
        加密方案1:
        
        安裝完 php-beast 後可以使用 tools 目錄下的 encode_files.php 來加密你的項目。使用 encode_files.php 之前先修改 tools 目錄下的 configure.ini 文件,如下:
        ; source path
        src_path = ""
        ; destination path
        dst_path = ""
        ; expire time
        expire = ""
        ; encrypt type (selection: DES, AES, BASE64)
        encrypt_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 開始加密項目。
        
        
        加密方案2:
        使用beast_encode_file()函數加密文件,函數原型如下:
        beast_encode_file(string $input_file, string $output_file, int expire_timestamp, int encrypt_type)。


        $input_file: 要加密的文件
        $output_file: 輸出的加密文件路徑
        $expire_timestamp: 文件過期時間戳
        $encrypt_type: 加密使用的算法(支持:BEAST_ENCRYPT_TYPE_DES、BEAST_ENCRYPT_TYPE_AES)


    參考鏈接:https://www.jianshu.com/p/7bacac6effe5

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章