Windows环境下使用php-beast加密php源代码

Windows环境下使用php-beast加密php源代码

PHP-Beast是一个源码加密的模块,调用该模块可以对PHP源码进行加密并在此模块下运行。

为什么要用PHP-Beast?
  有时候我们的代码会放到代理商上, 所以很有可能代码被盗取, 或者我们写了一个商业系统而且不希望代码开源, 所以这时候就需要加密我们的代码.
  另外PHP-Beast是完全免费和开源的, 当其不能完成满足你的需求时, 可以修改其代码而满足你的要求。

目前官方教程linux上的使用已经写的比较详细,但对于Windows环境下的使用还是比较笼统,故做此记录。

php-beast官方github地址:https://github.com/liexusong/php-beast


使用方法

  1. 下载GitHub已经释放出的版本软件,假设解压放在D:\php-beast文件内。

  2. 官方已经提供了关于 Windows DLL 的下载地址,根据你的php环境下载对应的版本,这是已经编译好的释出版本:点击查看

  3. 将下载下来的 .dll 文件如 php_beast_x86_nts.dll 放入php扩展模块的文件内,一般默认位于 ext 文件内,并修改 php.ini 文件,加入配置项:

extension=php_beast_x86_nts.dll

  重启php环境,让php加载 php-beast 模块。请注意官方提供的 .dll 文件的名字可能无法直接被加载引用,如果你确认已经正确加载php扩展模块配置并且出现无法加载的情况,可以按照php扩展模块的配置默认命名规则重命名文件如 php_beast.dll,再尝试重新加载。 如果你还不太了解 Windows 环境下php安装扩展模块,请参考我的另一篇博客:点击查看

  php成功加载后可看到如下结果图:
beast加载成功图

  1. 安装完 php-beast 后,配置 tools 目录下的 configure.ini 文件,如下:

; source path
src_path = “D:\php\src_path”  //要加密项目的路径

; destination path
dst_path = “D:\php\dst_path”  //保存加密后项目的路径

; expire time
expire = “2020-03-29 14:59:00”   //设置项目可使用的时间,格式是:YYYY-mm-dd HH:ii:ss

; encrypt type (selection: DES, AES, BASE64)
encrypt_type = “DES”  //加密的方式,支持的加密算法DES, AES, BASE64

  配置完成后,使用 encode_files.php来进行文件加密,其只会加密php文件,直接打开终端输入,先切换到 encode_files.php 文件目录内,假设位于 D:\php-beast\tools

>D:
>cd D:\php-beast\tools

  然后执行加密算法文件:

>php encode_files.php

  出现以下语句,说明加密成功

Source code path: D:\php\src_path
Destination code path: D:\php\dst_path
Expire time: 2099-10-18 22:00:00
------------- start process -------------
Processed encrypt files [100%] - 100%
Finish processed encrypt files, used 105.650371 seconds

  若出现以下语句:

Notice: Use of undefined constant BEAST_ENCRYPT_TYPE_DES - assumed 'BEAST_ENCRYPT_TYPE_DES' in D:\php-beast\tools\encode_files.php on line 136

Call Stack:
    0.0013     374624   1. {main}() D:\php-beast\tools\encode_files.php:0

Source code path: D:\php\src_path
Destination code path: D:\php\dst_path
Expire time: 2099-10-18 22:00:00
------------- start process -------------

Fatal error: Uncaught Error: Call to undefined function beast_encode_file() in D:\php-beast\tools\encode_files.php on line 81

Error: Call to undefined function beast_encode_file() in D:\php-beast\tools\encode_files.php on line 81

Call Stack:
    0.0013     374624   1. {main}() D:\php-beast\tools\encode_files.php:0
    0.7369     376384   2. encrypt_directory() D:\php-beast\tools\encode_files.php:153
    7.1738     377096   3. encrypt_directory() D:\php-beast\tools\encode_files.php:69
    7.1756     377808   4. encrypt_directory() D:\php-beast\tools\encode_files.php:69

   请注意该处错误是php系统环境路径的错误。此处php的路径,若是php系统环境的path路径不是你正在使用的已加载php-beast模块的php,假设你正在使用的php位于D:\php\php7.3.4nts内,而你的encode_files.php文件假设又位于D:\php-beast\tools,在不是位于相对文件内的情况下,请采用绝对路径的方式调用,按照以下方式调用:

>D:\php\php7.3.4nts/php.exe D:\php-beast\tools/encode_files.php

  成功后,你可以在项目的输出路径文件夹内打开已加密php文件,如下图所以:
加密的php文件展示

  此时表示加密源码成功,可尝试正常运行程序。


  若是你还不太了解php下的系统环境设置,请参考我的另一篇博客:点击查看

  当然你可能只想加密部分文件,那就只指定到该文件加密即可。或者不做文件配置,那也可以使用beast_encode_file()函数,输入项目的路径和输出的项目路径,其参数与配置基本一致。具体使用请参考官方说明。

  这里说一下,目前php-beast属于开源,支持的加密算法属于默认形式,为了更安全的调用,你应当修 header.c文件的头结构,更多的 制定自己的php-beast 内容请参考官方说明。

  头文件结构修改如下所示:

char encrypt_file_header_sign[] = {
	0xe8, 0x16, 0xa4, 0x0c,
	0xf2, 0xb2, 0x60, 0xee,
	0xb4, 0xcc, 0x72, 0x8e,//扩展的非官方的加密的文件头结构,也可以直接修改官方加密头结构
};
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
以下是使用JavaScript实现Beast64编码解码的示例代码: ```javascript // Base64编码表 const base64Table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; function beast64Encode(input) { let output = ''; let chr1, chr2, chr3, enc1, enc2, enc3, enc4; let i = 0; while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + base64Table.charAt(enc1) + base64Table.charAt(enc2) + base64Table.charAt(enc3) + base64Table.charAt(enc4); } return output; } function beast64Decode(input) { let output = ''; let chr1, chr2, chr3; let enc1, enc2, enc3, enc4; let i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ''); while (i < input.length) { enc1 = base64Table.indexOf(input.charAt(i++)); enc2 = base64Table.indexOf(input.charAt(i++)); enc3 = base64Table.indexOf(input.charAt(i++)); enc4 = base64Table.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } return output; } ``` 使用示例: ```javascript const input = 'hello world'; const encoded = beast64Encode(input); const decoded = beast64Decode(encoded); console.log(encoded); // 输出 SGVsbG8gd29ybGQ= console.log(decoded); // 输出 hello world ``` 以上代码实现了Beast64的编码和解码功能,可以将任意字符串转换为Beast64编码后的字符串,并将Beast64编码的字符串解码为原始字符串。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值