Jump to content
zbeng

C/C++ MD5 hash function

Recommended Posts

Posted

Easier than including the actual MD5 source in your projects.

char* md5(char *data, char *hash) {

HCRYPTPROV c_prov;

HCRYPTHASH c_hash;

BYTE raw_hash[64];

DWORD len = sizeof(raw_hash);

unsigned int i;

if(CryptAcquireContext(&c_prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT) &&

CryptCreateHash(c_prov, CALG_MD5, 0, 0, &c_hash) &&

CryptHashData(c_hash, data, strlen(data), 0) &&

CryptGetHashParam(c_hash, HP_HASHVAL, raw_hash, &len, 0) &&

((len * 2) + 1 <= 33)) {

for(i=0;i<len;i++) {

wsprintf(&hash[i * 2], TEXT("%02.2x"), raw_hash[i]);

}

} else {

return NULL;

}

hash[33] = '

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...