15 HANDLE hFile = CreateFileA(filePath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
16 if (hFile == INVALID_HANDLE_VALUE) {
24 WCHAR rgbDigits[] = L
"0123456789abcdef";
26 if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT) ||
27 !CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash)) {
34 while (ReadFile(hFile, rgbFile,
sizeof(rgbFile), &bytesRead, NULL)) {
35 if (bytesRead == 0)
break;
36 if (!CryptHashData(hHash, rgbFile, bytesRead, 0)) {
37 CryptReleaseContext(hProv, 0);
38 CryptDestroyHash(hHash);
45 if (CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &cbHash, 0)) {
46 for (
DWORD i = 0; i < cbHash; i++) {
47 fileHash[i * 2] = rgbDigits[rgbHash[i] >> 4];
48 fileHash[i * 2 + 1] = rgbDigits[rgbHash[i] & 0xf];
53 int size_needed = WideCharToMultiByte(CP_UTF8, 0, fileHash, -1, NULL, 0, NULL, NULL);
54 std::string
result(size_needed, 0);
55 WideCharToMultiByte(CP_UTF8, 0, fileHash, -1, &
result[0], size_needed, NULL, NULL);
56 std::string test = std::string(
result.begin(),
result.end());
57 CryptReleaseContext(hProv, 0);
58 CryptDestroyHash(hHash);