本文主要介绍使用Loadrunner进行字符串md5加密的方法。

使用Loadrunner进行md5比较简单,首先是加载md5.h头文件,后使用头文件中的加密函数即可。

1. md5.h头文件内容如下

#ifndef MD5_H
#define MD5_H
#ifdef __alpha
typedef unsigned int uint32;
#else
typedef unsigned long uint32;
#endif
struct MD5Context {uint32 buf[4];uint32 bits[2];unsigned char in[64];
};
extern void MD5Init();
extern void MD5Update();
extern void MD5Final();
extern void MD5Transform();
typedef struct MD5Context MD5_CTX;
#endif
#ifdef sgi
#define HIGHFIRST
#endif
#ifdef sun
#define HIGHFIRST
#endif
#ifndef HIGHFIRST
#define byteReverse(buf, len) /* Nothing */
#else
void byteReverse(buf, longs)unsigned char *buf; unsigned longs;
{uint32 t;do {t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |((unsigned) buf[1] << 8 | buf[0]);*(uint32 *) buf = t;buf += 4;} while (--longs);
}
#endif
void MD5Init(ctx)struct MD5Context *ctx;
{ctx->buf[0] = 0x67452301;ctx->buf[1] = 0xefcdab89;ctx->buf[2] = 0x98badcfe;ctx->buf[3] = 0x10325476;ctx->bits[0] = 0;ctx->bits[1] = 0;
}
void MD5Update(ctx, buf, len) struct MD5Context *ctx; unsigned char *buf; unsigned len;
{uint32 t;t = ctx->bits[0];if ((ctx->bits[0] = t + ((uint32) len << 3)) < t)ctx->bits[1]++;ctx->bits[1] += len >> 29;t = (t >> 3) & 0x3f;if (t) {unsigned char *p = (unsigned char *) ctx->in + t;t = 64 - t;if (len < t) {memcpy(p, buf, len);return;}memcpy(p, buf, t);byteReverse(ctx->in, 16);MD5Transform(ctx->buf, (uint32 *) ctx->in);buf += t;len -= t;}while (len >= 64) {memcpy(ctx->in, buf, 64);byteReverse(ctx->in, 16);MD5Transform(ctx->buf, (uint32 *) ctx->in);buf += 64;len -= 64;}memcpy(ctx->in, buf, len);
}
void MD5Final(digest, ctx)unsigned char digest[16]; struct MD5Context *ctx;
{unsigned count;unsigned char *p;count = (ctx->bits[0] >> 3) & 0x3F;p = ctx->in + count;*p++ = 0x80;count = 64 - 1 - count;if (count < 8) {memset(p, 0, count);byteReverse(ctx->in, 16);MD5Transform(ctx->buf, (uint32 *) ctx->in);memset(ctx->in, 0, 56);} else {memset(p, 0, count - 8);}byteReverse(ctx->in, 14);((uint32 *) ctx->in)[14] = ctx->bits[0];((uint32 *) ctx->in)[15] = ctx->bits[1];MD5Transform(ctx->buf, (uint32 *) ctx->in);byteReverse((unsigned char *) ctx->buf, 4);memcpy(digest, ctx->buf, 16);memset(ctx, 0, sizeof(ctx));
}
#define F1(x, y, z) (z ^ (x & (y ^ z)))
#define F2(x, y, z) F1(z, x, y)
#define F3(x, y, z) (x ^ y ^ z)
#define F4(x, y, z) (y ^ (x | ~z))
#define MD5STEP(f, w, x, y, z, data, s) ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
void MD5Transform(buf, in)uint32 buf[4]; uint32 in[16];
{register uint32 a, b, c, d;a = buf[0];b = buf[1];c = buf[2];d = buf[3];MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);buf[0] += a;buf[1] += b;buf[2] += c;buf[3] += d;
}
void GetMd5FromString(const char* s,char* resStr)
{struct MD5Context md5c;unsigned char ss[16];char subStr[3];int i;MD5Init( &md5c );MD5Update( &md5c, s, strlen(s) );MD5Final( ss, &md5c );strcpy(resStr,"");for( i=0; i<16; i++ ){sprintf(subStr, "%02x", ss[i] );itoa(ss[i],subStr,16);if (strlen(subStr)==1) {strcat(resStr,"0");}strcat(resStr,subStr);}strcat(resStr,"\0");
}

2. Loadrunner测试代码如下

#include "lrs.h"
#include "md5.h"Action()
{char *s="12345abc";
char *dest=(char *) malloc(10*1024);GetMd5FromString(s,dest);
lr_message(dest);return 0;
}

运行截图如下:

使用Loadrunner进行MD5加密示例

转载于:https://www.cnblogs.com/shengs/p/3790047.html

Loadrunner进行md5加密方法相关推荐

  1. Java实现Linux的md5加密,Linux_详细讲解:Linux系统GRUB的MD5加密方法,1、用grub-md5-crypt成生GRUB的md5密 - phpStudy...

    详细讲解:Linux系统GRUB的MD5加密方法 1.用grub-md5-crypt成生GRUB的md5密码: 通过grub-md5-crypt对GRUB的密码进行加密码运算,比如我们想设置grub的 ...

  2. php 易语言md5加密解密,详解易语言调用js实现md5加密方法

    易语言调用js需要用到拓展组件的脚本组件, 在窗口创建完毕的事件里给脚本组件初始化设置下脚本组件的语言属性,在这里以JScript为例: 脚本组件执行脚本的简单方法是:  脚本组件1.执行 ()  然 ...

  3. md5 ios java代码_IOS端與Java端MD5加密方法

    關於NSString的MD5加密,這不難,在網上可以搜到很多算法,主要是跟后台的統一會出問題,對同一段字符串,ios和java加密后的結果可能不一樣,很坑爹.現在貼一下ios端和后台java的代碼. ...

  4. IOS端与Java端MD5加密方法

    关于NSString的MD5加密,这不难,在网上可以搜到很多算法,主要是跟后台的统一会出问题,对同一段字符串,ios和java加密后的结果可能不一样.现在贴一下ios端和后台java的代码. java ...

  5. jmeter-Java关于MD5加密方法 以及16位32位互转

    MD5即Message-Digest Algorithm 5(信息-摘要算法5),用于确保信息传输完整一致.是计算机广泛使用的杂凑算法之一(又译摘要算法.哈希算法),主流编程语言普遍已有MD5实现.将 ...

  6. 前端使用vux中md5加密方法

    在进行页面的账号密码等输入信息传输的时候,需要用到加密方法,那么前端可以使用简单的md5来进行加密 若是在项目中引入了vux,则可以直接用vux中的md5加密方式, 首先导入:import { md5 ...

  7. password MD5加密方法

    password在表中不能明文的方式储存,应该对password进行加密 passwod MD5的加密的方法(直接调用这个方法就能实现MD5格式的加密): public String EncodeBy ...

  8. Python 技术篇-sha256()加密的使用方法,sha1、md5加密方法

    需要使用 hashlib 这个库,python 自带的,可以直接用. 要加密的数据需要先使用 encode() 进行编码. import hashlibdata = "你好" # ...

  9. java后台开发加密程序_Java后端实现MD5加密的方法

    前言 在我们开发是要考虑这个功能,当用户忘记密码的情况下,我们需要动态的发给他一个6位的随机密码,通过即时通,短信,微信等.并同时修改数据库中的原密码为这6位的随机密码.让用户再去修改密码. 同时在数 ...

最新文章

  1. 如何使用composer从Laravel中删除包?
  2. python核心编程第二版pdf_Python Book电子书pdf版合集 Python核心高级编程第二版
  3. SAP Cloud for Customer的Opportunity搜索前台实现原理
  4. 【转载】gcc 使用中常用的参数及命令
  5. Xftp5如何设置默认的文件夹
  6. [转载] 包含对象的json格式_如何把JSON数据格式转换为Python的类对象?
  7. linux 网络对时
  8. java applet插件下载_Java Applet.zip
  9. SM2258XT错误代码及中文翻译
  10. bat计算机清理原理,使用bat脚本清理系统垃圾的方法
  11. 使用百度开发者工具 4.0 搭建专属的小程序 IDE
  12. hp服务器主板显示51,HP Jetdirect打印服务器故障解决
  13. TypeError: FC() takes no arguments
  14. 【IT职场】如何成为T型甚至A型人物。
  15. shell编程实现一些小游戏
  16. 聊聊ThoughtWorks面试(郑大版 社招)+ PS:应届生简单流程介绍
  17. 排列组合之插板法及变形
  18. 重邮计算机专业取得奖项,重邮邹宇航:保研北大,囊括国内外40余个重量级奖项的科创达人...
  19. SqlException:ConnectionTimeout Expired. The timeout period elapsed during the post-login phase
  20. 中国蔬菜种子行业竞争动态与营销趋势预测报告2022-2027年

热门文章

  1. php insert failed,较大的MySQL INSERT语句导致PHP错误
  2. elementui datetimepicker 移动端_在 Gitee 收获 2.5K Star,前后端分离的 RuoYi 它来了
  3. array用法 numpy_NumPy总结(基础用法)
  4. MySQL5.7的date类型_Mysql5.7 虚拟列数据类型为DATE时,如何存入数据?
  5. 【java】牛客网刷题
  6. UML类图新手入门级介绍
  7. JavaScript中substr()和substring的区别
  8. 《图解HTTP》笔记之TCP/IP
  9. iOS音频——AudioToolbox
  10. iOS架构设计-URL缓存(上)