Call the function of the MD5 algorithm in Advapi32.dll.

xiaoxiao2021-03-06  49

Call the function of the MD5 algorithm in Advapi32.dll.

Basic Hash and RSA algorithms are implemented in Win2000 / XP Advapi32.dll, but Microsoft does not give a definition of functions and data.

The call to the MD5 algorithm will be demonstrated.

#include

/ * Data Structure for MD5 (Message-Digest) computation * / typef 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 md5digestlen 16

#define proto_list (list) List

/ ** MTS:. Each of these assumes MD5_CTX is locked against simultaneous use * / 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;

Const char * hex2asc (const byte * hex, int LEN) {static char ASC [4096 * 2]; INT i; for (i = 0; i > 4]; ASC [i * 2 1] = "0123456789abcdef" [HEX [I] & 0x0f];} ASC [i * 2] = '/ 0'; returnec;}

INT main () {md5_ctx ctx; unsigned char buf [4] = "1233"; Hinstance HDLL;

if ((hDLL = LoadLibrary ( "advapi32.dll"))> 0) {MD5Init = (PMD5Init) GetProcAddress (hDLL, "MD5Init"); MD5Update = (PMD5Update) GetProcAddress (hDLL, "MD5Update"); MD5Final = (PMD5Final GetProcAddress (HDLL, "MD5Final");

Md5init (& CTX); MD5UPDATE (& CTX, BUF, 4); MD5Final (& CTX);

Printf (HEX2ASC (CTX.Digest, 16);

} Return 0;} is not very simple. In addition, there are other algorithms such as RSA, DSA, SHA, etc.

The above code is debugged under WinXP SP1 / VC6.0

转载请注明原文地址:https://www.9cbs.com/read-116614.html

New Post(0)