公司的一个项目,老板问我能不能把源码给加密一下。之前也没做过类似的需求,其他人推荐了一个叫screw的php扩展,记录一下使用该扩展的过程

下载screw源码

git clone https://github.com/del-xiong/screw-plus.git

编译扩展和加密工具

在目录中执行php bin中的phpize命令自动生成扩展所需文件

$ /www/server/php/71/bin/phpize

Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303

执行./configure --with-php-config=[php config path] 进行配置,[php config path]是你的php-config的绝对路径(和phpize同一个目录)

$ sudo ./configure --with-php-config=/www/server/php/71/bin/php-config 

修改php_screw_plus.h中的CAKEY

#define CAKEY  "修改这里"
//如果只允许执行加过密的php文件 设置STRICT_MODE为1
//set STRICT_MODE to 1 if you only want the crypted php files to be executed
#define STRICT_MODE 0
const int maxBytes = 1024*1024*2;

执行make编译生成扩展

~/screw-plus$ make

进入tools目录执行make编译加密工具

~/screw-plus/tools$ make

加载screw扩展

生成的扩展在modules/php_screw_plus.so,直接修改php.ini,加上

    extension= ... /screw-plus/modules/php_screw_plus.so #建议写全路径

重启php-fpm服务,使用phpinfo()测试扩展是否加载成功。如果看到以下提示说明扩展生效了。

图片未加上。

加密php代码

进入tools目录,执行./screw [目录或文件] ,后面带上你要加密的目录或文件即可自动开始加密

~/screw-plus/tools$ ./screw /home/web/ #加密/home/web目录下的php文件

~/screw-plus/tools$ ./screw /home/web/ -d #加上-d解密/home/web目录下的php文件
Last modification:November 15th, 2018 at 09:38 am
If you think my article is useful to you, please feel free to appreciate