Júlio
asked on
c++ MD5 Hash WINAPI
Hello,
I'm trying to reproduce this example from MSDN: http://msdn.microsoft.com/en-us/library/aa382380%28VS.85%29.aspx
I'm using Windows 8.1 and i''m getting error 87 in CryptGetHashParam api, but i'm sure that i don't have a parameter problem:
I'm out of idea and Google is not helping. I want to get the md5 hash of my program in run-time and display it.
classes.hmain.cppmd5Functions.cpp
I'm trying to reproduce this example from MSDN: http://msdn.microsoft.com/en-us/library/aa382380%28VS.85%29.aspx
I'm using Windows 8.1 and i''m getting error 87 in CryptGetHashParam api, but i'm sure that i don't have a parameter problem:
bool Md5::HashCrypt(){
BOOL fileReaded = FALSE;
BYTE fileBuff[1024];
DWORD hash = BUFF_MD5;
BYTE hashBuff[MAX_PATH];
//read file content and fill hash object
while (fileReaded = ReadFile(fileHandle, fileBuff, BUFF_SIZE, &nBytes, NULL)){
if (!fileReaded){
ToClose();
cout << "ReadFile Fails." << endl;
return false;
}
if (nBytes == 0){
break;
}
if (!CryptHashData(cryptObject, fileBuff, nBytes, 0)){
ToClose();
cout << "CryptHashData Fails." << endl;
return false;
}
}
CHAR key[] = "0123456789abcdef";
if (CryptGetHashParam(crypHandle, HP_HASHSIZE, hashBuff, &hash, 0)){
cout << "-> MD5:\n " << endl;
for (DWORD i = 0; i < hash; i++){
printf("%c%c", key[hashBuff[i] >> 4],
key[hashBuff[i] & 0xf]);
}
ToClose();
return true;
}
else{
DWORD status = GetLastError();
ToClose();
cout << "CryptGetHashParam Fails. Error: " << status << endl;
return false;
}
}
I'm out of idea and Google is not helping. I want to get the md5 hash of my program in run-time and display it.
classes.hmain.cppmd5Functions.cpp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
he fixed it for me!
But my final MD5 doesn't looks like a MD5, so i'm asking in the same question about it.
He deserve the solution points.
But my final MD5 doesn't looks like a MD5, so i'm asking in the same question about it.
He deserve the solution points.
ASKER
but the result doesn't look like a MD5: