PHP源代码加密几种方法

如果你的PHP代码不想让人看到,你就需要把你项目的PHP源代码来加密一下,下面给大家介绍几种我最常用的PHP源代码加密方法:

一、Encipher
Encipher – PHP代码加密 | PHP源码加密

下载地址:https://github.com/uniqid/encipher

源码如下:

<?php
$app = str_replace(‘\\’, ‘/’, dirname(__FILE__));
require_once($app . ‘/lib/encipher.min.php’);

$original = $app . ‘/original’; //待加密的文件目录
$encoded  = $app . ‘/encoded’;  //加密后的文件目录
$encipher = new Encipher($original, $encoded);

/**
* 设置加密模式 false = 低级模式; true = 高级模式
* 低级模式不使用eval函数
* 高级模式使用了eval函数
*/
$encipher->advancedEncryption = true;

//设置注释内容
$encipher->comments = array(
   ‘Encipher – the PHP code encode tool’,
   ‘Version: 1.1.1’,
   ”,
   ‘The latest version of Encipher can be obtained from:’,
   ‘https://github.com/uniqid/encipher’
);

echo "<pre>\n";
$encipher->encode();
echo "</pre>\n";

二、php-beast
php-beast 为php一个扩展,可以方便快捷为php代码进行加密处理

1、安装

$ wget [https://github.com/liexusong/php-beast/archive/master.zip](https://github.com/liexusong/php-beast/archive/master.zip)
$ unzip master.zip
$ cd php-beast-master
$ phpize
$ ./configure –with-php-config=/usr/local/php/bin/php-config
$ sudo make && make install
编译好之后修改php.ini配置文件, 加入配置项: extension=beast.so,
重启php-fpm
$ service php-fpm restart

2、加密配置项

配置文件位于tool目录下configure.ini文件

src_path = ""  //加密项目的路径
dst_path = ""  //保存加密后的项目的路径
expire = "2020-12-31 24:00:00" //过期时间
encrypt_type = "DES" //加密方式 DES/AES/BASE64

3、执行加密操作

php encode_files.php

发表回复