Click here to Skip to main content
15,897,718 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Migrating from Win.MFC to Linux/??? Pin
bling17-Sep-14 8:54
bling17-Sep-14 8:54 
GeneralRe: Migrating from Win.MFC to Linux/??? Pin
Albert Holguin17-Sep-14 10:47
professionalAlbert Holguin17-Sep-14 10:47 
GeneralRe: Migrating from Win.MFC to Linux/??? Pin
Bram van Kampen17-Sep-14 13:33
Bram van Kampen17-Sep-14 13:33 
GeneralRe: Migrating from Win.MFC to Linux/??? Pin
SoMad17-Sep-14 14:04
professionalSoMad17-Sep-14 14:04 
GeneralRe: Migrating from Win.MFC to Linux/??? Pin
Albert Holguin17-Sep-14 16:40
professionalAlbert Holguin17-Sep-14 16:40 
GeneralRe: Migrating from Win.MFC to Linux/??? Pin
bling18-Sep-14 8:51
bling18-Sep-14 8:51 
AnswerRe: Migrating from Win.MFC to Linux/??? Pin
jschell17-Sep-14 10:01
jschell17-Sep-14 10:01 
QuestionCrypto API Question Pin
Drakesal16-Sep-14 5:24
Drakesal16-Sep-14 5:24 
I am crazying with a problem with the following function:

CStringA EncryptDecryptString(CStringA szString, BOOL bEncrypt)
{
       HCRYPTPROV hCryptProv      = NULL;
       LPCWSTR keyContainer       = _T("MyKeyContainer");

       if(CryptAcquireContext(&hCryptProv,keyContainer,NULL,PROV_RSA_FULL,0))
             if (GetLastError() == NTE_BAD_KEYSET)
                CryptAcquireContext(&hCryptProv,keyContainer,NULL,PROV_RSA_FULL,CRYPT_NEWKEYSET);

       HCRYPTHASH hHash = NULL;
       TCHAR szPassword[11]         = _T("Password");

       if(CryptCreateHash(hCryptProv,CALG_MD5,0,0,&hHash))
    {
             if(!CryptHashData(hHash,(BYTE *)szPassword,wcslen(szPassword),0))
             {
                    // reset hash object to NULL
                    CryptDestroyHash(hHash);
                    hHash = NULL;       
             }
    }

       HCRYPTKEY hKey = NULL;

       CryptDeriveKey(hCryptProv,CALG_RC4,hHash,0x00800000,&hKey);

       DWORD length= szString.GetLength() + 1;
       BYTE * cipherBlock= (BYTE *)malloc(length);
       memset(cipherBlock, 0, length);
       memcpy(cipherBlock, szString, length -1);

       if (bEncrypt)
             CryptEncrypt(hKey,0,TRUE,0,cipherBlock,&length,length);
       else
             CryptDecrypt(hKey,0,TRUE,0,cipherBlock,&length);

       CStringA szOutString(cipherBlock);

       if(cipherBlock) 
             free(cipherBlock); 
       if(hKey)
             CryptDestroyKey(hKey);
       if(hHash) 
          CryptDestroyHash(hHash);
       if(hCryptProv) 
          CryptReleaseContext(hCryptProv,0);

       return szOutString;
}


It's all ok with function, but sometimes when string is very very long during the Decryption i have only a part of string becouse the allocated memeory is not enought.

How can i alloc the correct amount of memory during the decryption phase?
AnswerRe: Crypto API Question Pin
Richard MacCutchan16-Sep-14 5:36
mveRichard MacCutchan16-Sep-14 5:36 
QuestionCMenus : How to use menu handles instead of menu resource ID when needed ? Pin
sdancer7515-Sep-14 20:45
sdancer7515-Sep-14 20:45 
AnswerRe: CMenus : How to use menu handles instead of menu resource ID when needed ? Pin
Richard MacCutchan15-Sep-14 21:19
mveRichard MacCutchan15-Sep-14 21:19 
AnswerRe: CMenus : How to use menu handles instead of menu resource ID when needed ? Pin
CPallini15-Sep-14 21:22
mveCPallini15-Sep-14 21:22 
GeneralRe: CMenus : How to use menu handles instead of menu resource ID when needed ? Pin
sdancer7515-Sep-14 22:07
sdancer7515-Sep-14 22:07 
GeneralRe: CMenus : How to use menu handles instead of menu resource ID when needed ? Pin
CPallini15-Sep-14 23:04
mveCPallini15-Sep-14 23:04 
GeneralRe: CMenus : How to use menu handles instead of menu resource ID when needed ? Pin
Richard MacCutchan16-Sep-14 2:30
mveRichard MacCutchan16-Sep-14 2:30 
GeneralRe: CMenus : How to use menu handles instead of menu resource ID when needed ? Pin
sdancer7516-Sep-14 21:35
sdancer7516-Sep-14 21:35 
GeneralRe: CMenus : How to use menu handles instead of menu resource ID when needed ? Pin
Richard MacCutchan16-Sep-14 21:57
mveRichard MacCutchan16-Sep-14 21:57 
GeneralRe: CMenus : How to use menu handles instead of menu resource ID when needed ? Pin
Richard MacCutchan16-Sep-14 2:29
mveRichard MacCutchan16-Sep-14 2:29 
GeneralRe: CMenus : How to use menu handles instead of menu resource ID when needed ? Pin
CPallini16-Sep-14 2:45
mveCPallini16-Sep-14 2:45 
QuestionPassing a class to a sprintf() and similar Pin
Crazy Joe Devola14-Sep-14 19:45
Crazy Joe Devola14-Sep-14 19:45 
AnswerRe: Passing a class to a sprintf() and similar Pin
CPallini14-Sep-14 20:01
mveCPallini14-Sep-14 20:01 
GeneralRe: Passing a class to a sprintf() and similar Pin
Crazy Joe Devola14-Sep-14 20:07
Crazy Joe Devola14-Sep-14 20:07 
GeneralRe: Passing a class to a sprintf() and similar Pin
CPallini15-Sep-14 2:15
mveCPallini15-Sep-14 2:15 
GeneralRe: Passing a class to a sprintf() and similar Pin
Richard MacCutchan16-Sep-14 2:59
mveRichard MacCutchan16-Sep-14 2:59 
GeneralRe: Passing a class to a sprintf() and similar Pin
CPallini16-Sep-14 3:11
mveCPallini16-Sep-14 3:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.