C++加密解密php代码的方法

本文实例讲述了C++加密解密php代码的方法。分享给大家供大家参考。具体实现方法如下:

#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "string.h"
char * key = "abcd";
PHP_FUNCTION(encode){
  long key_len = strlen(key);
  char * code, * encode_code;
  long code_len;
  if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &code, &code_len) == FAILURE){
    return;
  }
  encode_code = encode(code, code_len, key, key_len);
  RETURN_STRING(encode_code, 0);
}
PHP_FUNCTION(decode){
  long key_len = strlen(key);
  char * code, * decode_code;
  long code_len;
  if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &code, &code_len) == FAILURE){
    return;
  }
  decode_code = decode(code, code_len, key, key_len);
  RETURN_STRING(decode_code, 0);
}
PHP_FUNCTION(run){
  char * en_base64_code;
  long en_base64_code_len;
  char * decode_code;
  long key_len = strlen(key);
  char * eval_code;
  char * str_name;
  if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &en_base64_code, &en_base64_code_len) == FAILURE){
    return;
  }
  str_name = zend_make_compiled_string_description("phpencoder" TSRMLS_CC);
  decode_code = decode(en_base64_code, en_base64_code_len, key, key_len); //解码
  spprintf(&eval_code, 0, " ?>%s'", PHP_EOL);
    RETURN_FALSE;
  }
  efree(str_name);
  efree(eval_code);
  RETURN_TRUE;
}
inline char * encode(char * code, long code_len, char* key, long key_len){
  char * code_encode;
  int i;
  long offset = 0, ret_len;
  code_encode = strdup(code);
  for(i =0; i 
 

希望本文所述对大家的C++程序设计有所帮助。

你可能感兴趣的:(C++加密解密php代码的方法)