#include <stdio.h> #include <conio.h> #include <windows.h> typedef struct { ULONG i[2]; /* number of _bits_ handled mod 2^64 */ ULONG buf[4]; /* scratch buffer */ unsigned char in[64]; /* input buffer */ unsigned char digest[16]; /* actual digest after MD5Final call */ } MD5_CTX; #define PROTO_LIST(list) list typedef void (WINAPI* PMD5Init) PROTO_LIST((MD5_CTX *)); typedef void (WINAPI* PMD5Update) PROTO_LIST((MD5_CTX *, const unsigned char *, unsigned int)); typedef void (WINAPI* PMD5Final) PROTO_LIST((MD5_CTX *)); PMD5Init MD5Init = NULL; PMD5Update MD5Update = NULL; PMD5Final MD5Final = NULL; //功能:将数值转换为对应的十六进制ascii码,以便能够打印显示出来。 const char *Hex2ASC(const BYTE *Hex, int Len) { static char ASC[4096 * 2]; for (int i=0; i<Len; i++) { ASC[i * 2] = "0123456789ABCDEF"[Hex[i] >> 4]; ASC[i * 2 + 1] = "0123456789ABCDEF"[Hex[i] & 0x0F]; } ASC[i * 2] = '/0'; return ASC; } int main() { unsigned char buf[] = "admin888"; MD5_CTX ctx; HINSTANCE hDLL = LoadLibrary("advapi32.dll"); if ( hDLL != NULL ) { MD5Init = (PMD5Init)GetProcAddress(hDLL, "MD5Init"); MD5Update = (PMD5Update)GetProcAddress(hDLL, "MD5Update"); MD5Final = (PMD5Final)GetProcAddress(hDLL, "MD5Final"); MD5Init(&ctx); MD5Update(&ctx, buf, sizeof(buf)-1); MD5Final(&ctx); FreeLibrary(hDLL); printf("/"%s/"的MD5值为:%s", buf,Hex2ASC(ctx.digest, 16)); } getch(); return 0; }