// Buffer of the buffer output content of the input content bool md5digest (pbyte csbuffer, lptstr csoutbuffer, DWORD dwlen) {hcryptprov; hcrypthash hhash; byte bhash [0x7f]; DWORD dwhashlen = 32; // the MD5 algorithm always returns 16 bytes. DWORD cbcontent = dwlen; byte * pbcontent = new byte [dwlen]; memcpy (pbcontent, csbuffer, dwlen); If (cryptacquirecontext (& hcryptprov, null, null, prov_rsa_full, crypt_verifycontext | crypt_machine_keyset) {If (cryptcreatehash (hcryptprov, calg_md5, // algorithm identifier definitions see: wincrypt. h0, 0, & hhash) {If (crypthashdata (hhash, pbcontent, cbcontent, 0) {If (cryptgethashparam (hhash, hp_hashval, bhash, & dwhashlen, 0 )) {// make a string version of the numeric digest valuefor (INT I = 0; I <dwhashlen; I ++) {_ stprintf (csoutbuffer, _ T ("% S % 02x"), csoutbuffer, bhash [I]) ;}} elsereturn false;} else return false; cryptdestroyhash (hhash); cryptreleasecontext (hcryptprov, 0); // cstring STR; // Str. format (_ T ("% s"), csoutbuffer); // afxmessagebox (STR); Delete [] pbcontent; return true ;}
The MD5 value calculated for the ANSI encoding and Unicode encoding of the character "ABC" is different!