免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1169 | 回复: 2
打印 上一主题 下一主题

[其他] 加密解密php代码 [复制链接]

论坛徽章:
1
操作系统版块每日发帖之星
日期:2015-06-19 22:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-07-15 10:28 |只看该作者 |倒序浏览
[C/C++]代码
  1. #include "php.h"
  2. #include "php_ini.h"
  3. #include "ext/standard/info.h"
  4. #include "string.h"

  5. char * key = "abcd";


  6. PHP_FUNCTION(encode){
  7.     long key_len = strlen(key);
  8.     char * code, * encode_code;
  9.     long code_len;
  10.     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &code, &code_len) == FAILURE){
  11.         return;
  12.     }
  13.     encode_code = encode(code, code_len, key, key_len);
  14.     RETURN_STRING(encode_code, 0);
  15. }
  16. PHP_FUNCTION(decode){
  17.     long key_len = strlen(key);
  18.     char * code, * decode_code;
  19.     long code_len;
  20.     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &code, &code_len) == FAILURE){
  21.         return;
  22.     }
  23.     decode_code = decode(code, code_len, key, key_len);
  24.     RETURN_STRING(decode_code, 0);
  25. }
  26. PHP_FUNCTION(run){
  27.     char * en_base64_code;
  28.     long en_base64_code_len;
  29.      
  30.     char * decode_code;
  31.     long key_len = strlen(key);
  32.     char * eval_code;
  33.     char * str_name;

  34.     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &en_base64_code, &en_base64_code_len) == FAILURE){
  35.         return;
  36.     }

  37.     str_name = zend_make_compiled_string_description("phpencoder" TSRMLS_CC);

  38.     decode_code = decode(en_base64_code, en_base64_code_len, key, key_len); //解码
  39.     spprintf(&eval_code, 0, " ?>%s<?php ", decode_code);
  40.     free(decode_code);
  41.     if(zend_eval_string(eval_code, NULL, str_name TSRMLS_CC) == FAILURE){ //解析失败
  42.         efree(str_name);
  43.         efree(eval_code);
  44.         php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Please make sure '<?php' end with '?>'", PHP_EOL);
  45.         RETURN_FALSE;
  46.     }
  47.     efree(str_name);
  48.     efree(eval_code);
  49.     RETURN_TRUE;
  50.      
  51. }
  52. inline char * encode(char * code, long code_len, char* key, long key_len){
  53.     char * code_encode;
  54.     int i;
  55.     long offset = 0, ret_len;
  56.     code_encode = strdup(code);

  57.     for(i =0; i<code_len; i++){
  58.         if(offset == key_len){
  59.             offset = 0;
  60.         }
  61.         * (code_encode + i) = * (code + i) ^ * (key + offset);
  62.         offset ++;
  63.     }
  64.     return php_base64_encode(code_encode, code_len, &ret_len); //base64 加密
  65. }
  66. inline char * decode(char * code,long code_len, char* key, long key_len){
  67.     char * code_decode;
  68.     char * nobase_code;
  69.     int i;
  70.     long offset = 0, ret_len;
  71.     zend_bool strict = 0;

  72.     code_decode = strdup(code);

  73.     nobase_code = php_base64_decode_ex((unsigned char*)code, code_len, &ret_len, strict); //解密,ret_len 返回长度
  74.     for(i =0; i<ret_len; i++){
  75.         if(offset == key_len){
  76.             offset = 0;
  77.         }
  78.         * (code_decode + i) = * (nobase_code + i) ^ * (key + offset);
  79.         offset ++;
  80.     }
  81.     * (code_decode + i) = '\0';
  82.     return code_decode;
  83. }
复制代码

论坛徽章:
1
射手座
日期:2014-08-04 16:49:43
2 [报告]
发表于 2015-07-16 14:15 |只看该作者
php代码有什么好加密的, 如果有需要直接cgi啊...

论坛徽章:
89
水瓶座
日期:2014-04-01 08:53:31天蝎座
日期:2014-04-01 08:53:53天秤座
日期:2014-04-01 08:54:02射手座
日期:2014-04-01 08:54:15子鼠
日期:2014-04-01 08:55:35辰龙
日期:2014-04-01 08:56:36未羊
日期:2014-04-01 08:56:27戌狗
日期:2014-04-01 08:56:13亥猪
日期:2014-04-01 08:56:02亥猪
日期:2014-04-08 08:38:58程序设计版块每日发帖之星
日期:2016-01-05 06:20:00程序设计版块每日发帖之星
日期:2016-01-07 06:20:00
3 [报告]
发表于 2015-07-16 14:17 |只看该作者
貌似是一个php的扩展。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP