text: ///////////////////////////////////////////////////////////////////////////////
  // MIT License
  //
  // Copyright (c) 2020 nyfrk <nyfrk@gmx.net>
  //
  // Permission is hereby granted, free of charge, to any person obtaining a copy
  // of this software and associated documentation files (the "Software"), to deal
  // in the Software without restriction, including without limitation the rights
  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  // copies of the Software, and to permit persons to whom the Software is
  // furnished to do so, subject to the following conditions:
  //
  // The above copyright notice and this permission notice shall be included in all
  // copies or substantial portions of the Software.
  //
  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  // SOFTWARE.
  ///////////////////////////////////////////////////////////////////////////////
  
  #define WIN32_LEAN_AND_MEAN
  #include "md5.h"
  #include <Wincrypt.h>
  #include "tchar.h"
  
  #define BUFSIZE 1024
  
  SIZE_T MD5::ToString(LPTSTR out, SIZE_T sz) {
  	CONST TCHAR rgbDigits[] = _T("0123456789ABCDEF");
  	auto to = min(sz, MD5LEN * 2);
  	for (size_t i = 0; i < to; i++) {
  		auto& b = bytes[i / 2]; // byte takes two characters
  		out[i] = rgbDigits[(i % 2) ? (b & 0xF) : (b >> 4)];
  	}
  	if (to < sz) {
  		out[to] = '\0';
  		++to;
  	}
  	return to;
  }
  
  #pragma warning(push)
  #pragma warning( disable : 4706 )
  HRESULT ComputeMD5(LPCTSTR filename, MD5* out) {
  	// This is basically just the sample from here: 
  	// https://docs.microsoft.com/de-de/windows/win32/seccrypto/example-c-program--creating-an-md-5-hash-from-file-content?redirectedfrom=MSDN
  	// Note, you may change CALG_MD5 to CALG_SHA1 to get the SHA1 sum.
  
  	DWORD dwStatus = 0;
  	BOOL bResult = FALSE;
  	HCRYPTPROV hProv = 0;
  	HCRYPTHASH hHash = 0;
  	HANDLE hFile = NULL;
  	BYTE rgbFile[BUFSIZE];
  	DWORD cbRead = 0;
  	auto& rgbHash = out->bytes;
  	DWORD cbHash = 0;
  
  	hFile = CreateFile(filename,
  		GENERIC_READ,
  		FILE_SHARE_READ,
  		NULL,
  		OPEN_EXISTING,
  		FILE_FLAG_SEQUENTIAL_SCAN,
  		NULL);
  
  	if (INVALID_HANDLE_VALUE == hFile) {
  		dwStatus = GetLastError();
  		return dwStatus;
  	}
  
  	// Get handle to the crypto provider
  	if (!CryptAcquireContext(&hProv,
  		NULL,
  		NULL,
  		PROV_RSA_FULL,
  		CRYPT_VERIFYCONTEXT)) {
  		dwStatus = GetLastError();
  		CloseHandle(hFile);
  		return dwStatus;
  	}
  
  	if (!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash)) {
  		dwStatus = GetLastError();
  		CloseHandle(hFile);
  		CryptReleaseContext(hProv, 0);
  		return dwStatus;
  	}
  
  	while (bResult = ReadFile(hFile, rgbFile, BUFSIZE, &cbRead, NULL)) {
  		if (0 == cbRead) {
  			break;
  		}
  
  		if (!CryptHashData(hHash, rgbFile, cbRead, 0)) {
  			dwStatus = GetLastError();
  			CryptReleaseContext(hProv, 0);
  			CryptDestroyHash(hHash);
  			CloseHandle(hFile);
  			return dwStatus;
  		}
  	}
  #pragma warning(pop)
  
  	if (!bResult) {
  		dwStatus = GetLastError();
  		CryptReleaseContext(hProv, 0);
  		CryptDestroyHash(hHash);
  		CloseHandle(hFile);
  		return dwStatus;
  	}
  
  	cbHash = MD5LEN;
  	if (!CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &cbHash, 0)) {
  		dwStatus = GetLastError();
  	}
  
  	CryptDestroyHash(hHash);
  	CryptReleaseContext(hProv, 0);
  	CloseHandle(hFile);
  
  	return dwStatus;
  }