{"id":13793153,"url":"https://github.com/liexusong/php-beast","last_synced_at":"2025-05-15T18:07:31.103Z","repository":{"id":8853959,"uuid":"10562671","full_name":"liexusong/php-beast","owner":"liexusong","description":"PHP source code encrypt module (PHP源码加密扩展)","archived":false,"fork":false,"pushed_at":"2021-08-16T11:17:34.000Z","size":499,"stargazers_count":1720,"open_issues_count":88,"forks_count":510,"subscribers_count":120,"default_branch":"master","last_synced_at":"2025-03-31T22:18:20.387Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/liexusong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-06-08T02:46:51.000Z","updated_at":"2025-03-17T03:12:56.000Z","dependencies_parsed_at":"2022-07-12T12:49:46.951Z","dependency_job_id":null,"html_url":"https://github.com/liexusong/php-beast","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liexusong%2Fphp-beast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liexusong%2Fphp-beast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liexusong%2Fphp-beast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liexusong%2Fphp-beast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liexusong","download_url":"https://codeload.github.com/liexusong/php-beast/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247744332,"owners_count":20988783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T22:01:23.195Z","updated_at":"2025-04-07T23:08:02.540Z","avatar_url":"https://github.com/liexusong.png","language":"C","funding_links":[],"categories":["PHP 扩展"],"sub_categories":["PRC"],"readme":"\u003cpre\u003e\n        ____  __  ______     ____  _________   ___________\n       / __ \\/ / / / __ \\   / __ )/ ____/   | / ___/_  __/\n      / /_/ / /_/ / /_/ /  / __  / __/ / /| | \\__ \\ / /\n     / ____/ __  / ____/  / /_/ / /___/ ___ |___/ // /\n    /_/   /_/ /_/_/      /_____/_____/_/  |_/____//_/\n\n贡献者名字：\n@imaben (windows版本提供者)  https://github.com/imaben\n@pinguo-niulingyun (PHP7版本提供者) https://github.com/pinguo-niulingyun\n\nQQ交流群：239243332\n\u003c/pre\u003e\n\n\u003cb\u003eWindows DLL：\u003ca href=\"https://github.com/imaben/php-beast-binaries\"\u003e下载地址\u003c/a\u003e\u003c/b\u003e\n\n\u003cb\u003ephp-beast可以自定义加密模块，加密模块编写教程: \u003ca href=\"https://github.com/liexusong/php-beast/wiki/%E5%8A%A0%E5%AF%86%E6%A8%A1%E5%9D%97%E7%BC%96%E5%86%99%E6%95%99%E7%A8%8B\"\u003e点击\u003c/a\u003e\u003c/b\u003e\n\n\u003ch3\u003e编译安装如下:\u003c/h3\u003e\n\u003cpre\u003e\u003ccode\u003e\n$ wget https://github.com/liexusong/php-beast/archive/master.zip\n$ unzip master.zip\n$ cd php-beast-master\n$ phpize\n$ ./configure\n$ sudo make \u0026\u0026 make install\n\n编译好之后修改php.ini配置文件, 加入配置项: extension=beast.so, 重启php-fpm\n\u003c/code\u003e\u003c/pre\u003e\n\n\u003cpre\u003e温馨提示: 可以设置较大的缓存提高效率\u003c/pre\u003e\n\n\u003cp\u003e\u003cb\u003e使用php-beast的性能：\u003c/b\u003e\u003cbr/\u003e\u003cbr/\u003e\n\u003cimg src=\"http://git.oschina.net/liexusong/php-beast/raw/master/images/beast1.png?dir=0\u0026filepath=images/beast1.png\u0026oid=645b87003dada2eac4f1a9fcfd353aa0423f5711\u0026sha=7ec2a0ddc7780b2bab538d9f49d8b262f1bc37b7\" /\u003e\u003c/p\u003e\n\n\u003cp\u003e\u003cb\u003e不使用php-beast的性能：\u003c/b\u003e\u003cbr/\u003e\u003cbr/\u003e\n\u003cimg src=\"http://git.oschina.net/liexusong/php-beast/raw/master/images/beast2.png?dir=0\u0026filepath=images/beast2.png\u0026oid=3f07cff6dca34b22d8933ab0ea1740a0e4f37e34\u0026sha=7ec2a0ddc7780b2bab538d9f49d8b262f1bc37b7\" /\u003e\u003c/p\u003e\n\n配置项:\n\u003cpre\u003e\u003ccode\u003e\n beast.cache_size = size\n beast.log_file = \"path_to_log\"\n beast.log_user = \"user\"\n beast.log_level = \"debug\"\n beast.enable = On\n\u003c/code\u003e\u003c/pre\u003e\n\nbeast.log_level支持参数：\n\u003cpre\u003e\n 1. DEBUG\n 2. NOTICE\n 3. ERROR\n\u003c/pre\u003e\n\n支持的模块有：\n\u003cpre\u003e\n 1. AES\n 2. DES\n 3. Base64\n\u003c/pre\u003e\n\n通过测试环境:\n\u003cpre\u003e\u003ccode\u003e\n Nginx + Fastcgi + (PHP-5.2.x ~ PHP-7.1.x)\n\u003c/code\u003e\u003c/pre\u003e\n\n------------------------------\n\n## 怎么加密项目\n**加密方案1**\n\n安装完 `php-beast` 后可以使用 `tools` 目录下的 `encode_files.php` 来加密你的项目。使用 `encode_files.php` 之前先修改 `tools` 目录下的 `configure.ini` 文件，如下：\n```ini\n; source path\nsrc_path = \"\"\n\n; destination path\ndst_path = \"\"\n\n; expire time\nexpire = \"\"\n\n; encrypt type (selection: DES, AES, BASE64)\nencrypt_type = \"DES\"\n```\n`src_path` 是要加密项目的路径，`dst_path` 是保存加密后项目的路径，`expire` 是设置项目可使用的时间 (`expire` 的格式是：`YYYY-mm-dd HH:ii:ss`)。`encrypt_type`是加密的方式，选择项有：DES、AES、BASE64。\n修改完 `configure.ini` 文件后就可以使用命令 `php encode_files.php` 开始加密项目。\n\n**加密方案2**\n\n使用`beast_encode_file()`函数加密文件，函数原型如下：\u003cbr/\u003e\n`beast_encode_file(string $input_file, string $output_file, int expire_timestamp, int encrypt_type)`。\n\u003cpre\u003e\n1. $input_file: 要加密的文件\n2. $output_file: 输出的加密文件路径\n3. $expire_timestamp: 文件过期时间戳\n4. $encrypt_type: 加密使用的算法（支持：BEAST_ENCRYPT_TYPE_DES、BEAST_ENCRYPT_TYPE_AES）\n\u003c/pre\u003e\n\n------------------------------\n\n## 制定自己的php-beast\n\n`php-beast` 有多个地方可以定制的，以下一一列出：\n\n*1.* 使用 `header.c` 文件可以修改 `php-beast` 加密后的文件头结构，这样网上的解密软件就不能认识我们的加密文件，就不能进行解密，增加加密的安全性。\n\n*2.* `php-beast` 提供只能在指定的机器上运行的功能。要使用此功能可以在 `networkcards.c` 文件添加能够运行机器的网卡号，例如：\n```c\nchar *allow_networkcards[] = {\n\t\"fa:16:3e:08:88:01\",\n    NULL,\n};\n```\n这样设置之后，`php-beast` 扩展就只能在 `fa:16:3e:08:88:01` 这台机器上运行。另外要注意的是，由于有些机器网卡名可能不一样，所以如果你的网卡名不是 `eth0` 的话，可以在 `php.ini` 中添加配置项： `beast.networkcard = \"xxx\"` 其中 `xxx` 就是你的网卡名，也可以配置多张网卡，如：`beast.networkcard = \"eth0,eth1,eth2\"`。\n\n*3.* 使用 `php-beast` 时最好不要使用默认的加密key，因为扩展是开源的，如果使用默认加密key的话，很容易被人发现。所以最好编译的时候修改加密的key，`aes模块` 可以在 `aes_algo_handler.c` 文件修改，而 `des模块` 可以在 `des_algo_handler.c` 文件修改。\n\n------------------------------\n\n## 开启debug模式\n可以在configure时加上 `--enable-beast-debug` 选项来开启debug模式。开启debug模式后需要在php.ini配置文件中加入配置项：`beast.debug_path` 和 `beast.debug_mode`。`beast.debug_mode` 用于指定是否使用debug模式，而 `beast.debug_path` 用于输出解密后的php脚本源码。这样就可以在 `beast.debug_path` 目录中看到php-beast解密后的源代码，可以方便知道扩展解密是否正确。\n\n## 开启禁止执行未加密的脚本\n可以在configure时加上 `--enable-execute-normal-script=off` 选项来禁止执行未加密的PHP脚本。\n\n------------------------------\n\n## 函数列表\n*1.* beast_encode_file(): 用于加密一个文件\n\n*2.* beast_avail_cache(): 获取可以缓存大小\n\n*3.* beast_support_filesize(): 获取beast支持的最大可加密文件大小\n\n*4.* beast_file_expire(): 获取一个文件的过期时间\n\n*5.* beast_clean_cache(): 清空beast的所有缓存(如果有文件更新, 可以使用此函数清空缓存)\n\n------------------------------\n\n## 常见问题\n\n*1.* linux：如果出现502错误，一般是由于GCC版本太低导致，请先升级GCC再安装本模块。\n\n*2.* Windows：IIS环境下FastCGI进程异常退出：尝试将IIS的运行用户从ApplicationPoolIdentity改为LocalSystem\n\n------------------------------\n\n### 我们的公众号\n\n![](https://image-static.segmentfault.com/376/558/3765589661-607fef350658b_fix732)\n\n------------------------------\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliexusong%2Fphp-beast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliexusong%2Fphp-beast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliexusong%2Fphp-beast/lists"}