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

2020-01-06 13:27:20于丽

易采站长站为您分析C++加密解密php代码的方法,实例分析了基于C++实现加密解密的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了C++加密解密php代码的方法。。具体实现方法如下:

 

 
  1. #include "php.h"  #include "php_ini.h" 
  2. #include "ext/standard/info.h"  #include "string.h" 
  3. char * key = "abcd";  PHP_FUNCTION(encode){ 
  4. long key_len = strlen(key);  char * code, * encode_code; 
  5. long code_len;  if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &code, &code_len) == FAILURE){ 
  6. return;  } 
  7. encode_code = encode(code, code_len, key, key_len);  RETURN_STRING(encode_code, 0); 
  8. }  PHP_FUNCTION(decode){ 
  9. long key_len = strlen(key);  char * code, * decode_code; 
  10. long code_len;  if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &code, &code_len) == FAILURE){ 
  11. return;  } 
  12. decode_code = decode(code, code_len, key, key_len);  RETURN_STRING(decode_code, 0); 
  13. }  PHP_FUNCTION(run){ 
  14. char * en_base64_code;  long en_base64_code_len; 
  15. char * decode_code;  long key_len = strlen(key); 
  16. char * eval_code;  char * str_name; 
  17. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &en_base64_code, &en_base64_code_len) == FAILURE){  return; 
  18. }  str_name = zend_make_compiled_string_description("phpencoder" TSRMLS_CC); 
  19. decode_code = decode(en_base64_code, en_base64_code_len, key, key_len); //解码  spprintf(&eval_code, 0, " ?>%s<?php ", decode_code); 
  20. free(decode_code);  if(zend_eval_string(eval_code, NULL, str_name TSRMLS_CC) == FAILURE){ //解析失败 
  21. efree(str_name);  efree(eval_code); 
  22. php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Please make sure '<?php' end with '?>'", PHP_EOL);  RETURN_FALSE;