MD5校验值program(1) (2008-06-09 09:11:28)

hegangben
2025-07-14 / 0 评论 / 0 阅读 / 正在检测是否收录...

具体的一个MD5实现

=============================头文件Security.h===============================================

// 下列 ifdef 块是创建使从 DLL 导出更简单的

// 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 SECURITY_EXPORTS

// 符号编译的。在使用此 DLL 的

// 任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将

// SECURITY_API 函数视为是从此 DLL 导入的,而此 DLL 则将用此宏定义的

// 符号视为是被导出的。

//在使用该类的地方包含本文件即可

ifdef SECURITY_EXPORTS

define SECURITY_API __declspec(dllexport)

else

define SECURITY_API __declspec(dllimport)

endif

typedef unsigned char *POINTER;

typedef unsigned short int UINT2;

typedef unsigned long int UINT4;

define PROTO_LIST(list) list

typedef struct _MD5_CTX

{

UINT4 state[4];

UINT4 count[2];

unsigned char buffer[64];

} MD5_CTX;

static unsigned char PADDING[64]= {

0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

};

define S11 7

define S12 12

define S13 17

define S14 22

define S21 5

define S22 9

define S23 14

define S24 20

define S31 4

define S32 11

define S33 16

define S34 23

define S41 6

define S42 10

define S43 15

define S44 21

define F(x, y, z) (((x) & (y)) | ((~x) & (z)))

define G(x, y, z) (((x) & (z)) | ((y) & (~z)))

define H(x, y, z) ((x) ^ (y) ^ (z))

define I(x, y, z) ((y) ^ ((x) | (~z)))

define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))

define FF(a, b, c, d, x, s, ac) { (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac);(a) = ROTATE_LEFT ((a), (s)); (a) += (b); }

define GG(a, b, c, d, x, s, ac) { (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }

define HH(a, b, c, d, x, s, ac) { (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }

define II(a, b, c, d, x, s, ac) { (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }

define TEST_BLOCK_LEN 1000

define TEST_BLOCK_COUNT 1000

// 此类是从 Security.dll 导出的

class SECURITY_API CSecurity

{

public:

CSecurity(void);

void CSecurity::MD5( const char string ,char lpMD5StringBuffer ) ;

private:

void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));

void MD5_memcpy PROTO_LIST ((POINTER, POINTER, size_t));

void MD5_memset PROTO_LIST ((POINTER, int, size_t));

void MD5Init PROTO_LIST ((MD5_CTX *));

void MD5Update PROTO_LIST ((MD5_CTX , unsigned char , size_t));

void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));

void MDTimeTrial PROTO_LIST ((void));

void StringAddOne PROTO_LIST ((char *));

void Encode PROTO_LIST ((unsigned char , UINT4 , size_t));

void Decode PROTO_LIST ((UINT4 , unsigned char , size_t));

};

===============================Security.cpp====================================================

// Security.cpp : 定义 DLL 应用程序的入口点。

//

include "stdafx.h"

include

include

include

include

include

include "Security.h"

BOOL APIENTRY DllMain( HANDLE hModule,

DWORD  ul_reason_for_call, 

LPVOID lpReserved

)

{

switch (ul_reason_for_call)

{

case DLL_PROCESS_ATTACH:

case DLL_THREAD_ATTACH:

case DLL_THREAD_DETACH:

case DLL_PROCESS_DETACH:

break;

}

return TRUE;

}

0

评论 (0)

取消