Crypt Library Demo 1.00

CryptographyExt.cpp

Go to the documentation of this file.
00001 /* This file is part of Crypt Library Demo application developed by Mihai MOGA.
00002 
00003 Image Converter is free software: you can redistribute it and/or modify it
00004 under the terms of the GNU General Public License as published by the Open
00005 Source Initiative, either version 3 of the License, or any later version.
00006 
00007 Image Converter is distributed in the hope that it will be useful, but
00008 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00009 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
00010 
00011 You should have received a copy of the GNU General Public License along with
00012 Crypt Library Demo.  If not, see <http://www.opensource.org/licenses/gpl-3.0.html>*/
00013 
00014 // CryptographyExt.cpp : Demo for Microsoft's Crypt Library functions.
00015 // Author: Stefan-Mihai MOGA, e-mail: contact@mihaimoga.com, phone: +40745497982
00016 
00017 #include "stdafx.h"
00018 #include "CryptographyExt.h"
00019 
00020 #define SECURITY_WIN32
00021 #include <Security.h>
00022 #pragma comment(lib, "secur32")
00023 
00024 #include <nb30.h>
00025 #pragma comment(lib, "netapi32")
00026 
00027 #include <wincrypt.h>
00028 #pragma comment(lib, "crypt32")
00029 #pragma comment(lib, "advapi32")
00030 
00031 #ifdef _DEBUG
00032 #define new DEBUG_NEW
00033 #endif
00034 
00035 void TraceLastError(LPCTSTR lpszLibrary, LPCTSTR lpszOperation, DWORD dwLastError)
00036 {
00037     //Display a message and the last error in the TRACE. 
00038     LPVOID lpszErrorBuffer = NULL;
00039     CString strLastError;
00040 
00041     ::FormatMessage(
00042         FORMAT_MESSAGE_ALLOCATE_BUFFER | 
00043         FORMAT_MESSAGE_FROM_SYSTEM | 
00044         FORMAT_MESSAGE_IGNORE_INSERTS,
00045         NULL,
00046         dwLastError,
00047         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
00048         (LPTSTR) &lpszErrorBuffer,
00049         0,
00050         NULL);
00051 
00052     strLastError.Format(_T("[%s] %s: %s\n"), lpszLibrary, lpszOperation, lpszErrorBuffer);
00053 
00054     // free alocated buffer by FormatMessage
00055     LocalFree(lpszErrorBuffer); 
00056 
00057     //Display the last error.
00058     OutputDebugString(strLastError);
00059 }
00060 
00061 CString GetComputerID()
00062 {
00063     CString strComputerID;
00064     DWORD dwLength = MAX_STR_BUFFER;
00065     TCHAR lpszComputer[MAX_STR_BUFFER] = { 0 };
00066     if (GetComputerNameEx(ComputerNameDnsFullyQualified, lpszComputer, &dwLength))
00067     {
00068         lpszComputer[dwLength] = 0;
00069         strComputerID = lpszComputer;
00070     }
00071     else
00072     {
00073         if (GetComputerName(lpszComputer, &dwLength))
00074         {
00075             lpszComputer[dwLength] = 0;
00076             strComputerID = lpszComputer;
00077         }
00078         else
00079         {
00080             strComputerID =  _T("MihaiMoga");
00081         }
00082     }
00083     return strComputerID;
00084 }
00085 
00086 BOOL ConvertHexaToBinary(CLongBinary * pTargetBinary, CLongBinary * pSourceBinary)
00087 {
00088     BYTE nDataValue;
00089     UINT nDataIndex;
00090     TCHAR chUpperNibble;
00091     TCHAR chLowerNibble;
00092 
00093     const CString strHexaDigit = _T("0123456789ABCDEF");
00094 
00095     if (!pTargetBinary || !pSourceBinary)
00096         return FALSE;
00097 
00098     pTargetBinary->m_hData = NULL;
00099     pTargetBinary->m_dwDataLength = pSourceBinary->m_dwDataLength / 2 / sizeof(TCHAR);
00100 
00101     if (!pSourceBinary->m_dwDataLength)
00102         return TRUE;
00103 
00104     pTargetBinary->m_hData = GlobalAlloc(GPTR, pTargetBinary->m_dwDataLength + sizeof(BYTE));
00105 
00106     TCHAR * pSourceArray = (TCHAR *) GlobalLock(pSourceBinary->m_hData);
00107     BYTE * pTargetArray = (BYTE *) GlobalLock(pTargetBinary->m_hData);
00108     ASSERT((pSourceArray != NULL) && (pTargetArray != NULL));
00109 
00110     for (UINT nIndex = 0; nIndex < pTargetBinary->m_dwDataLength; nIndex++)
00111     {
00112         nDataIndex = nIndex << 1; // multiply be two
00113 
00114         chUpperNibble = pSourceArray[nDataIndex];
00115         ASSERT(strHexaDigit.Find(chUpperNibble) != -1);
00116         nDataValue = (BYTE)(strHexaDigit.Find(chUpperNibble) * 0x10);
00117 
00118         chLowerNibble = pSourceArray[nDataIndex + 1];
00119         ASSERT(strHexaDigit.Find(chLowerNibble) != -1);
00120         nDataValue = (BYTE)(nDataValue + strHexaDigit.Find(chLowerNibble));
00121 
00122         pTargetArray[nIndex] = nDataValue;
00123     }
00124 
00125     VERIFY(GlobalUnlock(pTargetBinary->m_hData));
00126     VERIFY(GlobalUnlock(pSourceBinary->m_hData));
00127 
00128     return TRUE;
00129 }
00130 
00131 BOOL ConvertHexaToBinary(LPBYTE lpszOutputBuffer, DWORD dwOutputLength, LPCTSTR lpszInputBuffer, DWORD dwInputLength)
00132 {
00133     ASSERT(lpszOutputBuffer != NULL);
00134     ASSERT(lpszInputBuffer != NULL);
00135     ASSERT(dwInputLength <= (2 * dwOutputLength));
00136 
00137     BYTE nDataValue;
00138     UINT nDataIndex;
00139     TCHAR chUpperNibble;
00140     TCHAR chLowerNibble;
00141 
00142     const CString strHexaDigit = _T("0123456789ABCDEF");
00143 
00144     for (UINT nIndex = 0; nIndex < dwInputLength / 2; nIndex++)
00145     {
00146         nDataIndex = nIndex << 1; // multiply be two
00147 
00148         chUpperNibble = lpszInputBuffer[nDataIndex];
00149         ASSERT(strHexaDigit.Find(chUpperNibble) != -1);
00150         nDataValue = (BYTE)(strHexaDigit.Find(chUpperNibble) * 0x10);
00151 
00152         chLowerNibble = lpszInputBuffer[nDataIndex + 1];
00153         ASSERT(strHexaDigit.Find(chLowerNibble) != -1);
00154         nDataValue = (BYTE)(nDataValue + strHexaDigit.Find(chLowerNibble));
00155 
00156         lpszOutputBuffer[nIndex] = nDataValue;
00157     }
00158 
00159     return TRUE;
00160 }
00161 
00162 BOOL ConvertBinaryToHexa(CLongBinary * pTargetBinary, CLongBinary * pSourceBinary)
00163 {
00164     BYTE nDataValue;
00165     UINT nDataIndex;
00166 
00167     const CString strHexaDigit = _T("0123456789ABCDEF");
00168 
00169     if (!pTargetBinary || !pSourceBinary)
00170         return FALSE;
00171 
00172     pTargetBinary->m_hData = NULL;
00173     pTargetBinary->m_dwDataLength = pSourceBinary->m_dwDataLength * 2 * sizeof(TCHAR);
00174 
00175     if (!pSourceBinary->m_dwDataLength)
00176         return TRUE;
00177 
00178     pTargetBinary->m_hData = GlobalAlloc(GPTR, pTargetBinary->m_dwDataLength + sizeof(TCHAR));
00179 
00180     BYTE * pSourceArray = (BYTE *) GlobalLock(pSourceBinary->m_hData);
00181     TCHAR * pTargetArray = (TCHAR *) GlobalLock(pTargetBinary->m_hData);
00182     ASSERT((pSourceArray != NULL) && (pTargetArray != NULL));
00183 
00184     for (UINT nIndex = 0; nIndex < pSourceBinary->m_dwDataLength; nIndex++)
00185     {
00186         nDataIndex = nIndex << 1;  // multiply be two
00187         nDataValue = pSourceArray[nIndex];
00188 
00189         pTargetArray[nDataIndex] = strHexaDigit.GetAt((nDataValue & 0xFF) / 0x10);
00190 
00191         pTargetArray[nDataIndex + 1] = strHexaDigit.GetAt((nDataValue & 0xFF) % 0x10);
00192     }
00193 
00194     VERIFY(GlobalUnlock(pTargetBinary->m_hData));
00195     VERIFY(GlobalUnlock(pSourceBinary->m_hData));
00196 
00197     return TRUE;
00198 }
00199 
00200 BOOL ConvertBinaryToHexa(LPTSTR lpszOutputBuffer, DWORD dwOutputLength, LPBYTE lpszInputBuffer, DWORD dwInputLength)
00201 {
00202     ASSERT(lpszOutputBuffer != NULL);
00203     ASSERT(lpszInputBuffer != NULL);
00204     ASSERT(dwOutputLength >= (2 * dwInputLength));
00205 
00206     BYTE nDataValue;
00207     UINT nDataIndex;
00208 
00209     const CString strHexaDigit = _T("0123456789ABCDEF");
00210 
00211     for (UINT nIndex = 0; nIndex < dwInputLength; nIndex++)
00212     {
00213         nDataIndex = nIndex << 1;  // multiply be two
00214         nDataValue = lpszInputBuffer[nIndex];
00215 
00216         lpszOutputBuffer[nDataIndex] = strHexaDigit.GetAt((nDataValue & 0xFF) / 0x10);
00217 
00218         lpszOutputBuffer[nDataIndex + 1] = strHexaDigit.GetAt((nDataValue & 0xFF) % 0x10);
00219     }
00220 
00221     lpszOutputBuffer[2 * dwInputLength] = _T('\0');
00222 
00223     return TRUE;
00224 }
00225 
00226 BOOL GetChecksumBuffer(ALG_ID nAlgorithm, LPBYTE lpszOutputBuffer, DWORD& dwOutputLength, LPBYTE lpszInputBuffer, DWORD dwInputLength)
00227 {
00228     BOOL retVal = FALSE;
00229 
00230     ASSERT(lpszOutputBuffer != NULL);
00231     ASSERT(dwOutputLength != 0);
00232     ASSERT(lpszInputBuffer != NULL);
00233     ASSERT(dwInputLength != 0);
00234 
00235     HCRYPTPROV hCryptProv = NULL;
00236     HCRYPTHASH hCryptHash = NULL;
00237 
00238     if (CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
00239     {
00240         if (CryptCreateHash(hCryptProv, nAlgorithm, NULL, 0, &hCryptHash))
00241         {
00242             if (CryptHashData(hCryptHash, lpszInputBuffer, dwInputLength, 0))
00243             {
00244                 if (CryptGetHashParam(hCryptHash, HP_HASHVAL, lpszOutputBuffer, &dwOutputLength, 0))
00245                 {
00246                     retVal = TRUE;
00247                 }
00248                 else
00249                 {
00250                     TraceLastError(CRYPT_LIBRARY_NAME, _T("CryptGetHashParam"), GetLastError());
00251                 }
00252             }
00253             else
00254             {
00255                 TraceLastError(CRYPT_LIBRARY_NAME, _T("CryptHashData"), GetLastError());
00256             }
00257             VERIFY(CryptDestroyHash(hCryptHash));
00258         }
00259         else
00260         {
00261             TraceLastError(CRYPT_LIBRARY_NAME, _T("CryptCreateHash"), GetLastError());
00262         }
00263         VERIFY(CryptReleaseContext(hCryptProv, 0));
00264     }
00265     else
00266     {
00267         TraceLastError(CRYPT_LIBRARY_NAME, _T("CryptAcquireContext"), GetLastError());
00268     }
00269 
00270     return retVal;
00271 }
00272 
00273 BOOL GetChecksumString(ALG_ID nAlgorithm, CString& strResult, CString strBuffer)
00274 {
00275     BOOL retVal = FALSE;
00276     const int nChecksumLength = ((CALG_MD5 == nAlgorithm) ? MD5CHECKSUM_LENGTH : SHA1CHECKSUM_LENGTH);
00277 
00278     DWORD dwOutput = nChecksumLength;
00279     BYTE* lpszOutput = new BYTE[nChecksumLength];
00280 
00281     const DWORD dwInput = (strBuffer.GetLength() + 1) * sizeof(TCHAR);
00282     BYTE* lpszInput = new BYTE[dwInput];
00283     ::CopyMemory(lpszInput, strBuffer.GetBuffer(), dwInput);
00284     strBuffer.ReleaseBuffer();
00285 
00286     if (GetChecksumBuffer(nAlgorithm, lpszOutput, dwOutput, lpszInput, dwInput))
00287     {
00288         LPTSTR lpszString = strResult.GetBufferSetLength(2 * nChecksumLength + 1);
00289         if (ConvertBinaryToHexa(lpszString, 2 * nChecksumLength + 1, lpszOutput, dwOutput))
00290         {
00291             strResult.ReleaseBuffer();
00292             retVal = TRUE;
00293         }
00294     }
00295 
00296     if (lpszInput != NULL)
00297     {
00298         delete lpszInput;
00299         lpszInput = NULL;
00300     }
00301 
00302     if (lpszOutput != NULL)
00303     {
00304         delete lpszOutput;
00305         lpszOutput = NULL;
00306     }
00307 
00308     return retVal;
00309 }
00310 
00311 BOOL GetChecksumFile(ALG_ID nAlgorithm, CString& strResult, CString strPathName)
00312 {
00313     BOOL retVal = FALSE;
00314     const int nChecksumLength = ((CALG_MD5 == nAlgorithm) ? MD5CHECKSUM_LENGTH : SHA1CHECKSUM_LENGTH);
00315 
00316     DWORD dwOutput = nChecksumLength;
00317     BYTE* lpszOutput = new BYTE[nChecksumLength];
00318 
00319     BYTE* lpszInput = NULL;
00320     try
00321     {
00322         CFile pInputFile(strPathName, CFile::modeRead | CFile::typeBinary);
00323         const UINT dwInput = (UINT)pInputFile.GetLength();
00324         if (dwInput > 0)
00325         {
00326             lpszInput = new BYTE[dwInput];
00327             if (dwInput == pInputFile.Read(lpszInput, dwInput))
00328             {
00329                 if (GetChecksumBuffer(nAlgorithm, lpszOutput, dwOutput, lpszInput, dwInput))
00330                 {
00331                     LPTSTR lpszString = strResult.GetBufferSetLength(2 * nChecksumLength + 1);
00332                     if (ConvertBinaryToHexa(lpszString, 2 * nChecksumLength + 1, lpszOutput, dwOutput))
00333                     {
00334                         strResult.ReleaseBuffer();
00335                         retVal = TRUE;
00336                     }
00337                 }
00338             }
00339         }
00340         pInputFile.Close();
00341     }
00342     catch (CFileException * pFileException)
00343     {
00344         TCHAR lpszError[MAX_STR_BUFFER] = { 0 };
00345         pFileException->GetErrorMessage(lpszError, MAX_STR_BUFFER);
00346         pFileException->Delete();
00347         OutputDebugString(lpszError);
00348         retVal = FALSE;
00349     }
00350 
00351     if (lpszInput != NULL)
00352     {
00353         delete lpszInput;
00354         lpszInput = NULL;
00355     }
00356 
00357     if (lpszOutput != NULL)
00358     {
00359         delete lpszOutput;
00360         lpszOutput = NULL;
00361     }
00362 
00363     return retVal;
00364 }
00365 
00366 BOOL EncryptBuffer(ALG_ID nAlgorithm, LPBYTE lpszOutputBuffer, DWORD& dwOutputLength, LPBYTE lpszInputBuffer, DWORD dwInputLength, LPBYTE lpszSecretKey, DWORD dwSecretKey)
00367 {
00368     BOOL retVal = FALSE;
00369     DWORD dwHowManyBytes = dwInputLength;
00370 
00371     ASSERT(lpszOutputBuffer != NULL);
00372     ASSERT(dwOutputLength != 0);
00373     ASSERT(lpszInputBuffer != NULL);
00374     ASSERT(dwInputLength != 0);
00375     ASSERT(lpszSecretKey != NULL);
00376     ASSERT(dwSecretKey != 0);
00377 
00378     HCRYPTPROV hCryptProv = NULL;
00379     HCRYPTHASH hCryptHash = NULL;
00380     HCRYPTKEY hCryptKey = NULL;
00381 
00382     ::CopyMemory(lpszOutputBuffer, lpszInputBuffer, dwHowManyBytes);
00383 
00384     if (CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
00385     {
00386         if (CryptCreateHash(hCryptProv, CALG_MD5, NULL, 0, &hCryptHash))
00387         {
00388             if (CryptHashData(hCryptHash, lpszSecretKey, dwSecretKey, 0))
00389             {
00390                 if (CryptDeriveKey(hCryptProv, nAlgorithm, hCryptHash, CRYPT_EXPORTABLE, &hCryptKey))
00391                 {
00392                     if (CryptEncrypt(hCryptKey, NULL, TRUE, 0, lpszOutputBuffer, &dwHowManyBytes, dwOutputLength))
00393                     {
00394                         dwOutputLength = dwHowManyBytes;
00395                         retVal = TRUE;
00396                     }
00397                     else
00398                     {
00399                         TraceLastError(CRYPT_LIBRARY_NAME, _T("CryptEncrypt"), GetLastError());
00400                     }
00401                     VERIFY(CryptDestroyKey(hCryptKey));
00402                 }
00403                 else
00404                 {
00405                     TraceLastError(CRYPT_LIBRARY_NAME, _T("CryptDeriveKey"), GetLastError());
00406                 }
00407             }
00408             else
00409             {
00410                 TraceLastError(CRYPT_LIBRARY_NAME, _T("CryptHashData"), GetLastError());
00411             }
00412             VERIFY(CryptDestroyHash(hCryptHash));
00413         }
00414         else
00415         {
00416             TraceLastError(CRYPT_LIBRARY_NAME, _T("CryptCreateHash"), GetLastError());
00417         }
00418         VERIFY(CryptReleaseContext(hCryptProv, 0));
00419     }
00420     else
00421     {
00422         TraceLastError(CRYPT_LIBRARY_NAME, _T("CryptAcquireContext"), GetLastError());
00423     }
00424 
00425     return retVal;
00426 }
00427 
00428 BOOL EncryptFile(ALG_ID nAlgorithm, CString strOutputName, CString strInputName, LPBYTE lpszSecretKey, DWORD dwSecretKey)
00429 {
00430     BOOL retVal = FALSE;
00431 
00432     BYTE* lpszOutput = NULL;
00433     BYTE* lpszInput = NULL;
00434     try
00435     {
00436         CFile pInputFile(strInputName, CFile::modeRead | CFile::typeBinary);
00437         const UINT dwInput = (UINT)pInputFile.GetLength();
00438         if (dwInput > 0)
00439         {
00440             lpszInput = new BYTE[dwInput];
00441             if (dwInput == pInputFile.Read(lpszInput, dwInput))
00442             {
00443                 DWORD dwOutput = dwInput + MAX_CRYPT_TAIL;
00444                 lpszOutput = new BYTE[dwOutput];
00445                 if (EncryptBuffer(nAlgorithm, lpszOutput, dwOutput, lpszInput, dwInput, lpszSecretKey, dwSecretKey))
00446                 {
00447                     CFile pOutputFile(strOutputName, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);
00448                     pOutputFile.Write(lpszOutput, dwOutput);
00449                     pOutputFile.Close();
00450                     retVal = TRUE;
00451                 }
00452             }
00453         }
00454         pInputFile.Close();
00455     }
00456     catch (CFileException * pFileException)
00457     {
00458         TCHAR lpszError[MAX_STR_BUFFER] = { 0 };
00459         pFileException->GetErrorMessage(lpszError, MAX_STR_BUFFER);
00460         pFileException->Delete();
00461         OutputDebugString(lpszError);
00462         retVal = FALSE;
00463     }
00464 
00465     if (lpszInput != NULL)
00466     {
00467         delete lpszInput;
00468         lpszInput = NULL;
00469     }
00470 
00471     if (lpszOutput != NULL)
00472     {
00473         delete lpszOutput;
00474         lpszOutput = NULL;
00475     }
00476 
00477     return retVal;
00478 }
00479 
00480 BOOL DecryptBuffer(ALG_ID nAlgorithm, LPBYTE lpszOutputBuffer, DWORD& dwOutputLength, LPBYTE lpszInputBuffer, DWORD dwInputLength, LPBYTE lpszSecretKey, DWORD dwSecretKey)
00481 {
00482     BOOL retVal = FALSE;
00483     DWORD dwHowManyBytes = dwInputLength;
00484 
00485     ASSERT(lpszOutputBuffer != NULL);
00486     ASSERT(dwOutputLength != 0);
00487     ASSERT(lpszInputBuffer != NULL);
00488     ASSERT(dwInputLength != 0);
00489     ASSERT(lpszSecretKey != NULL);
00490     ASSERT(dwSecretKey != 0);
00491 
00492     HCRYPTPROV hCryptProv = NULL;
00493     HCRYPTHASH hCryptHash = NULL;
00494     HCRYPTKEY hCryptKey = NULL;
00495 
00496     ::CopyMemory(lpszOutputBuffer, lpszInputBuffer, dwHowManyBytes);
00497 
00498     if (CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
00499     {
00500         if (CryptCreateHash(hCryptProv, CALG_MD5, NULL, 0, &hCryptHash))
00501         {
00502             if (CryptHashData(hCryptHash, lpszSecretKey, dwSecretKey, 0))
00503             {
00504                 if (CryptDeriveKey(hCryptProv, nAlgorithm, hCryptHash, CRYPT_EXPORTABLE, &hCryptKey))
00505                 {
00506                     if (CryptDecrypt(hCryptKey, NULL, TRUE, 0, lpszOutputBuffer, &dwHowManyBytes))
00507                     {
00508                         dwOutputLength = dwHowManyBytes;
00509                         retVal = TRUE;
00510                     }
00511                     else
00512                     {
00513                         TraceLastError(CRYPT_LIBRARY_NAME, _T("CryptDecrypt"), GetLastError());
00514                     }
00515                     VERIFY(CryptDestroyKey(hCryptKey));
00516                 }
00517                 else
00518                 {
00519                     TraceLastError(CRYPT_LIBRARY_NAME, _T("CryptDeriveKey"), GetLastError());
00520                 }
00521             }
00522             else
00523             {
00524                 TraceLastError(CRYPT_LIBRARY_NAME, _T("CryptHashData"), GetLastError());
00525             }
00526             VERIFY(CryptDestroyHash(hCryptHash));
00527         }
00528         else
00529         {
00530             TraceLastError(CRYPT_LIBRARY_NAME, _T("CryptCreateHash"), GetLastError());
00531         }
00532         VERIFY(CryptReleaseContext(hCryptProv, 0));
00533     }
00534     else
00535     {
00536         TraceLastError(CRYPT_LIBRARY_NAME, _T("CryptAcquireContext"), GetLastError());
00537     }
00538 
00539     return retVal;
00540 }
00541 
00542 BOOL DecryptFile(ALG_ID nAlgorithm, CString strOutputName, CString strInputName, LPBYTE lpszSecretKey, DWORD dwSecretKey)
00543 {
00544     BOOL retVal = FALSE;
00545 
00546     BYTE* lpszOutput = NULL;
00547     BYTE* lpszInput = NULL;
00548     try
00549     {
00550         CFile pInputFile(strInputName, CFile::modeRead | CFile::typeBinary);
00551         const UINT dwInput = (UINT)pInputFile.GetLength();
00552         if (dwInput > 0)
00553         {
00554             lpszInput = new BYTE[dwInput];
00555             if (dwInput == pInputFile.Read(lpszInput, dwInput))
00556             {
00557                 DWORD dwOutput = dwInput + MAX_CRYPT_TAIL;
00558                 lpszOutput = new BYTE[dwOutput];
00559                 if (DecryptBuffer(nAlgorithm, lpszOutput, dwOutput, lpszInput, dwInput, lpszSecretKey, dwSecretKey))
00560                 {
00561                     CFile pOutputFile(strOutputName, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);
00562                     pOutputFile.Write(lpszOutput, dwOutput);
00563                     pOutputFile.Close();
00564                     retVal = TRUE;
00565                 }
00566             }
00567         }
00568         pInputFile.Close();
00569     }
00570     catch (CFileException * pFileException)
00571     {
00572         TCHAR lpszError[MAX_STR_BUFFER] = { 0 };
00573         pFileException->GetErrorMessage(lpszError, MAX_STR_BUFFER);
00574         pFileException->Delete();
00575         OutputDebugString(lpszError);
00576         retVal = FALSE;
00577     }
00578 
00579     if (lpszInput != NULL)
00580     {
00581         delete lpszInput;
00582         lpszInput = NULL;
00583     }
00584 
00585     if (lpszOutput != NULL)
00586     {
00587         delete lpszOutput;
00588         lpszOutput = NULL;
00589     }
00590 
00591     return retVal;
00592 }
 All Classes Files Functions Variables Enumerator Defines