设为首页收藏本站

LUPA开源社区

 找回密码
 注册
文章 帖子 博客
LUPA开源社区 首页 业界资讯 软件追踪 查看内容

PHP源码加密扩展PHP-Beast V2.0发布

2016-5-4 21:53| 发布者: joejoe0332| 查看: 1159| 评论: 0|原作者: oschina|来自: oschina

摘要: 此次更新主要支持自定义加密算法,你可以通过编写自己的加密算法嵌入到php-beast中。你可以使用非公开的加密算法来加密你的php脚本,从而增加解密的难道. 具体编写教程可以参考链接:https://github.com/liexusong/ph ...

此次更新主要支持自定义加密算法,你可以通过编写自己的加密算法嵌入到php-beast中。

你可以使用非公开的加密算法来加密你的php脚本,从而增加解密的难道. 具体编写教程可以参考链接:

https://github.com/liexusong/php-beast/blob/master/write_a_encrypt_handler_module.md

-----------------------------------------------------------------------------------------------------

加密模块编写教程

一、首先创建一个.c的文件。例如我们要编写一个使用base64加密的模块,可以创建一个名叫base64_algo_handler.c的文件。然后在文件添加如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "beast_module.h"
 
int base64_encrypt_handler(char *inbuf, int len, char **outbuf, int *outlen)
{
    ...
}
 
int base64_decrypt_handler(char *inbuf, int len, char **outbuf, int *outlen)
{
    ...
}
 
void base64_free_handler(void *ptr)
{
    ...
}
 
struct beast_ops base64_handler_ops = {
    .name = "base64-algo",
    .encrypt = base64_encrypt_handler,
    .decrypt = base64_decrypt_handler,
    .free = base64_free_handler,
};

模块必须实现3个方法,分别是:encrypt、decrypt、free方法。

  • 1) encrypt方法负责把inbuf字符串加密,然后通过outbuf输出给beast。

  • 2) decrypt方法负责把加密数据inbuf解密,然后通过outbuf输出给beast。

  • 3) free方法负责释放encrypt和decrypt方法生成的数据。

二、写好我们的加密模块后,需要在global_algo_modules.c添加我们模块的信息。代码如下:

1
2
3
4
5
6
7
8
9
10
#include <stdlib.h>
#include "beast_module.h"
 
extern struct beast_ops des_handler_ops;
 
struct beast_ops *ops_handler_list[] = {
    &des_handler_ops,
    &base64_handler_ops, /* 这里是我们的模块信息 */
    NULL,
};

三、修改config.m4文件,修改倒数第二行,如下代码:

1
PHP_NEW_EXTENSION(beast, beast.c des_algo_handler.c beast_mm.c spinlock.c cache.c beast_log.c global_algo_modules.c base64_algo_handler.c, $ext_shared)

加粗的代码是我们添加的,这里加入的是我们模块的文件名。
现在大功告成了,可以编译试下。如果要使用我们刚编写的加密算法来加密php文件,可以修改php.ini文件的配置项,如下:

1
beast.encrypt_handler = "base64-algo"

名字就是我们模块的name。


酷毙

雷人

鲜花

鸡蛋

漂亮
  • 快毕业了,没工作经验,
    找份工作好难啊?
    赶紧去人才芯片公司磨练吧!!

最新评论

关于LUPA|人才芯片工程|人才招聘|LUPA认证|LUPA教育|LUPA开源社区 ( 浙B2-20090187 浙公网安备 33010602006705号   

返回顶部