LoadRunner calling the MD5 method

Source: Internet
Author: User

LoadRunner calling the MD5 method

Previous/Next 2011-04-29 11:25:12/personal Category: LoadRunner

View (958)/comment (0)/Rating (0/ 0)

In the request parameter of a project, there is one parameter that requires MD5 encryption. In Google search for some of the LR call MD5 method data. The reference material implements the parameter MD5 encryption. Now the method is summarized as follows:

1. First generate the MD5 algorithm in the C compiler md5.h file, add this md5.h file in VUser Generator, and then add # include "global.h" header file in Md5.h

2. Call the MD5 method: Lr_output_message ("%s", CMd5 ("Test"))

---can also generate a DLL from the MD5 method, and then call the DLL in LR. (This method has not been tried)

The MD5 method is as follows:

#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-&GT;BUF[1] = 0xefcdab89;
CTX-&GT;BUF[2] = 0x98badcfe;
CTX-&GT;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-&GT;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) [] = ctx->bits[0];
((UInt32 *) ctx->in) [] = ctx->bits[1];
Md5transform (Ctx->buf, (UInt32 *) ctx->in);
Bytereverse ((unsigned char *) CTX-&GT;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;
}
char* CMd5 (const char* s)
{
struct Md5context md5c;
unsigned char ss[16];
Char substr[3],resstr[33];
int i;
Md5init (&AMP;MD5C);
Md5update (&md5c, S, strlen (s));
Md5final (SS, &AMP;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, "n");
return resstr;
}

LoadRunner calling the MD5 method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.