troubleshooting Question

c++ MD5 Hash WINAPI

Avatar of Júlio
JúlioFlag for Brazil asked on
C++Windows 8
3 Comments1 Solution1101 ViewsLast Modified:

I'm trying to reproduce this example from MSDN:

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){
			cout << "ReadFile Fails." << endl;
			return false;
		if (nBytes == 0){
		if (!CryptHashData(cryptObject, fileBuff, nBytes, 0)){
			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]);

		return true;
		DWORD status = GetLastError();
		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.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros