In my spare time I have implemented a simple Visual C++ application to show the power of Microsoft Crypt Library. The following functions have been implemented and tested using MD5 checksum and RC4 encryption/decryption:
The demo application is using the computer's name as secret key for encryption/decryption. Target OS: 32bit Windows 2000, XP, Vista, 7. License: GNU General Public License version 3 (GPLv3).
Here is sample usage of the program
- BOOL GetChecksumBuff er(ALG_ID nAlgorithm, LPBYTE lpszOutputBuffe r, DWORD& dwOutputLength, LPBYTE lpszInputBuffer , DWORD dwInputLength);
- BOOL GetChecksumStri ng(ALG_ID nAlgorithm, CString& strResult, CString strBuffer);
- BOOL GetChecksumFile (ALG_ID nAlgorithm, CString& strResult, CString strPathName);
- BOOL EncryptBuffer(A LG_ID nAlgorithm, LPBYTE lpszOutputBuffe r, DWORD& dwOutputLength, LPBYTE lpszInputBuffer , DWORD dwInputLength, LPBYTE lpszSecretKey, DWORD dwSecretKey);
- BOOL EncryptFile(ALG _ID nAlgorithm, CString strOutputName, CString strInputName, LPBYTE lpszSecretKey, DWORD dwSecretKey);
- BOOL DecryptBuffer(A LG_ID nAlgorithm, LPBYTE lpszOutputBuffe r, DWORD& dwOutputLength, LPBYTE lpszInputBuffer , DWORD dwInputLength, LPBYTE lpszSecretKey, DWORD dwSecretKey);
- BOOL DecryptFile(ALG _ID nAlgorithm, CString strOutputName, CString strInputName, LPBYTE lpszSecretKey, DWORD dwSecretKey);
The demo application is using the computer's name as secret key for encryption/decryption. Target OS: 32bit Windows 2000, XP, Vista, 7. License: GNU General Public License version 3 (GPLv3).
Here is sample usage of the program
Code:
CString strBuffer1 = _T("abc"), strResult1;
VERIFY(GetChecksumString(CALG_MD5, strResult1, strBuffer1));
TRACE(_T("MD5(%s) => %s\n"), strBuffer1, strResult1);
CString strBuffer2 = _T("abc"), strResult2;
VERIFY(GetChecksumFile(CALG_SHA1, strResult2, _T("D:\\AddressBook.csv")));
TRACE(_T("SHA1(%s) => %s\n"), strBuffer2, strResult2);
CString strSecretKey = GetComputerID();
LPBYTE lpszSecretKey = (LPBYTE)(LPCTSTR)strSecretKey;
DWORD dwSecretKey = (strSecretKey.GetLength() + 1) * sizeof(TCHAR);
CString strFilename = _T("D:\\AddressBook.csv");
CString strEncrypt = _T("D:\\AddressBook.rc4");
CString strDecrypt = _T("D:\\AddressBook.txt");
VERIFY(EncryptFile(CALG_RC4, strEncrypt, strFilename, lpszSecretKey, dwSecretKey));
VERIFY(DecryptFile(CALG_RC4, strDecrypt, strEncrypt, lpszSecretKey, dwSecretKey));
Comment