20BinaryDataToHexString(
const BYTE *hash, DWORD &hashSize,
24 for (DWORD i = 0;
i < hashSize; ++
i)
26 wsprintfW(p, L
"%.2x", hash[i]);
41CalculateMD5(
const char *data, DWORD dataSize,
42 BYTE **hash, DWORD &hashSize)
47 if (!CryptAcquireContext(&hProv,
nullptr,
nullptr, PROV_RSA_FULL,
50 if (NTE_BAD_KEYSET != GetLastError())
56 if (!CryptAcquireContext(&hProv,
nullptr,
nullptr, PROV_RSA_FULL,
57 CRYPT_VERIFYCONTEXT | CRYPT_NEWKEYSET))
63 if (!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash))
68 if (!CryptHashData(hHash,
reinterpret_cast<const BYTE*
>(data),
74 DWORD dwCount =
sizeof(DWORD);
75 if (!CryptGetHashParam(hHash, HP_HASHSIZE, (
BYTE *)&hashSize,
81 *hash =
new BYTE[hashSize];
82 ZeroMemory(*hash, hashSize);
83 if (!CryptGetHashParam(hHash, HP_HASHVAL, *hash, &hashSize, 0))
90 CryptDestroyHash(hHash);
95 CryptReleaseContext(hProv,0);
113 size_t filePathLen = wcslen(filePath);
120 if (filePath[filePathLen -1] == L
'\\' ||
121 filePath[filePathLen - 1] == L
'/')
130 WCHAR *lowercasePath =
new WCHAR[filePathLen + 2];
131 memset(lowercasePath, 0, (filePathLen + 2) *
sizeof(WCHAR));
132 wcsncpy(lowercasePath, filePath, filePathLen + 1);
133 _wcslwr(lowercasePath);
137 if (!CalculateMD5(
reinterpret_cast<const char*
>(lowercasePath),
141 delete[] lowercasePath;
144 delete[] lowercasePath;
146 LPCWSTR baseRegPath = L
"SOFTWARE\\LibreOffice\\MaintenanceService\\";
147 wcsncpy(registryPath, baseRegPath, MAX_PATH);
148 BinaryDataToHexString(hash, hashSize,
149 registryPath + wcslen(baseRegPath));
BOOL CalculateRegistryPathFromFilePath(const LPCWSTR filePath, LPWSTR registryPath)
Converts a file path into a unique registry location for cert storage.
const wchar_t *typedef BOOL