I need to compare hash values of two strings. I use string "template" for testing. But I got different hash values for this string so it is always not the same. I use CryptoApi and MD4
int _tmain(int argc, _TCHAR* argv[])
{
std::hash_map<int,int> table;
HCRYPTPROV hProv1,hProv2;
BYTE *pbBuffer1=(BYTE*)"template";//data to hash
DWORD dwBufferLen1=strlen((char*)pbBuffer1)+1;
HCRYPTHASH hHash1,hHash2;
//first hash
CryptAcquireContext(&hProv1,NULL,NULL,PROV_RSA_AES,0);
CryptCreateHash(hProv1,CALG_MD4,0,0,&hHash1);
CryptHashData(hHash1,pbBuffer1,dwBufferLen1,0);
/*---------*/
BYTE *pbBuffer2=(BYTE*)"template";//data to hash
DWORD dwBufferLen2=strlen((char*)pbBuffer2)+1;
//second hash
CryptAcquireContext(&hProv2,NULL,NULL,PROV_RSA_AES,0);
CryptCreateHash(hProv2,CALG_MD4,0,0,&hHash2);
CryptHashData(hHash2,pbBuffer2,dwBufferLen2,0);
if (hHash1==hHash2)
printf("The Same\n");
else printf("Not same\n");
/*---------*/
std::cout<<hHash1<<std::endl;
std::cout<<hHash2<<std::endl;
if (hProv1)
CryptReleaseContext(hProv1,0);
if (hProv2)
CryptReleaseContext(hProv2,0);
system("pause");
return 0;
}
For example hash value in hHash1
691136
Hash value in hHash2
691216
::in C.