Loadrunner中进行md5加密

 
 

1.打印时间戳

web_save_timestamp_param("tStamp",LAST);//打印时间戳
lr_output_message("#打印时间:%s",lr_eval_string("{tStamp}"));//把时间戳转换字符串

2.md5加密(下载

方法一:加入md5.h文件到项目中,需要注意Action中用到的变量必须在global.h中先声明

image

此方法运行速度慢。

方法二:加载编译好的dll

根据OpenSSL帮助,下载OpenSSL 1.1.1i 32bit,参照文章C/C++使用openssl进行摘要和加密解密(md5, sha256, des, rsa)和Generating RSA256 Signature in Loadrunner using C language

global.h中先声明变量:

unsigned char * input;
char sign0[32];
char encodedStr[32];
unsigned char mdStr[33]= {0};
char buf[65]= {0};
char tmp[3]= {0};
int i;

Action中调用

lr_load_dll("libcrypto-1_1.dll");
input = (unsigned char*)calloc(130,sizeof(unsigned char));
strcpy((char*)input,"&password");

MD5(input, strlen(input), mdStr);
strcpy(encodedStr,(const char *)mdStr);


for (i = 0; i < 32; i++)
{
sprintf(tmp, "%02x", mdStr[i]);
strcat(buf, tmp);
}
buf[32] = '\0';
strcpy(sign0,buf);
lr_output_message("%s",sign0);

if (input != NULL)
{
free(input);
input = NULL;
}

此方法运行速度快。

posted on 2020-04-21 18:03  农夫山药  阅读(431)  评论(0编辑  收藏  举报