Created
August 17, 2016 08:50
-
-
Save mobius/a2f9847bbce474f71d6478948ef34d25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool PatchManager::GetMD5(const u8 *pBuffer, u32 uBufLen, u8 *rgbHash) | |
{ | |
BOOL bResult = FALSE; | |
HCRYPTPROV hProv = 0; | |
HCRYPTHASH hHash = 0; | |
DWORD cbRead = 0; | |
DWORD cbHash = 0; | |
CHAR rgbDigits[] = "0123456789ABCDEF"; | |
// Get handle to the crypto provider | |
if (!CryptAcquireContext(&hProv, | |
NULL, | |
NULL, | |
PROV_RSA_FULL, | |
CRYPT_VERIFYCONTEXT)) | |
{ | |
return false; | |
} | |
if (!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash)) | |
{ | |
CryptReleaseContext(hProv, 0); | |
return false; | |
} | |
u32 uIdx = 0; | |
while (uIdx < uBufLen) | |
{ | |
u32 cbRead = 1024; | |
if (uIdx + cbRead > uBufLen) | |
{ | |
cbRead = uBufLen - uIdx; | |
} | |
if (!CryptHashData(hHash, pBuffer + uIdx, cbRead, 0)) | |
{ | |
CryptReleaseContext(hProv, 0); | |
CryptDestroyHash(hHash); | |
return false; | |
} | |
uIdx += cbRead; | |
} | |
cbHash = 16; | |
if (CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &cbHash, 0)) | |
{ | |
bResult = TRUE; | |
} | |
CryptDestroyHash(hHash); | |
CryptReleaseContext(hProv, 0); | |
return bResult; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment