Click here to Skip to main content
15,900,378 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRefreshBoundData behaves strange !! Pin
Hesham Amin29-Nov-03 9:01
Hesham Amin29-Nov-03 9:01 
GeneralC help! Pin
Anonymous29-Nov-03 8:53
Anonymous29-Nov-03 8:53 
GeneralRe: C help! Pin
JWood29-Nov-03 18:36
JWood29-Nov-03 18:36 
GeneralRe: C help! Pin
Anonymous30-Nov-03 10:19
Anonymous30-Nov-03 10:19 
GeneralWindowFromPoint() Pin
__Cerb29-Nov-03 7:45
__Cerb29-Nov-03 7:45 
GeneralRe: WindowFromPoint() Pin
DaFrawg29-Nov-03 9:13
DaFrawg29-Nov-03 9:13 
GeneralRe: WindowFromPoint() Pin
Michael Dunn29-Nov-03 9:14
sitebuilderMichael Dunn29-Nov-03 9:14 
GeneralARRGGHHH stupid CryptoAPI (CryptEncrypt) Pin
(Steven Hicks)n+129-Nov-03 7:24
(Steven Hicks)n+129-Nov-03 7:24 
The first time i call EncryptString (below) I pass "<password>asdf" it encrypts to to be a length of 25 and encrypts it right. But when i try to encrypt a 2539 length string it returns a string of a length of 225 and only partically encrypted. Why is this happening and how do I fix it?


CString CEncyptionClass::EncryptString(CString m_strUnencryptedString)
{
//variables
//Date:11 22 03
CString m_strResultingText;
HCRYPTPROV hProv = NULL;
HCRYPTKEY hKey = NULL;
HCRYPTHASH hHash = NULL;
DWORD dwLength;
BYTE * pbBuffer;
LPTSTR m_tContents=ConvertCStringToChar(m_strUnencryptedString);

TCHAR szLocalPassword[] = _T("alongrandompassword");
//

// Get handle to user default provider.
if (CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0))
{
// Create hash object.
if (CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash))
{
// Hash password string.
dwLength = _tcslen(szLocalPassword);
if (CryptHashData(hHash, (BYTE *)szLocalPassword, dwLength, 0))
{
// Create block cipher session key based on hash of the password.
if (CryptDeriveKey(hProv, CALG_RC4, hHash, CRYPT_EXPORTABLE, &hKey))
{

dwLength= _tcslen(m_tContents);

pbBuffer=(BYTE*)malloc(dwLength);

if (pbBuffer != NULL)
{
memcpy(pbBuffer, m_tContents, dwLength);

if (CryptEncrypt(hKey, 0, true, 0, pbBuffer, &dwLength, dwLength))
{
m_strResultingText.Format("%s",pbBuffer);

CString strShow;
strShow.Format("After: %s \r\n(%s)\r\n %d %d", m_strResultingText,m_tContents,strlen((const char*) pbBuffer) ,dwLength);
MessageBox(strShow);
}
free(pbBuffer);

}
CryptDestroyKey(hKey); // Release provider handle.
}
}
CryptDestroyHash(hHash); // Destroy session key.
}
CryptReleaseContext(hProv, 0);
}


return m_strResultingText;
}



-Steven Hicks

CPA

CodeProjectAddict

Actual Linux Penguins were harmed in the creation of this message.

More tutorials: Ltpb.8m.com: Tutorials |404Browser.com (Download Link)

GeneralSetWindowsHookEx and HINSTANCE; Pin
Bo Hunter29-Nov-03 6:39
Bo Hunter29-Nov-03 6:39 
GeneralRe: SetWindowsHookEx and HINSTANCE; Pin
Anonymous29-Nov-03 7:14
Anonymous29-Nov-03 7:14 
GeneralHelp with going through text file. Pin
Snyp29-Nov-03 6:28
Snyp29-Nov-03 6:28 
GeneralRe: Help with going through text file. Pin
BaldwinMartin29-Nov-03 19:29
BaldwinMartin29-Nov-03 19:29 
GeneralRe: Help with going through text file. Pin
Snyp30-Nov-03 7:08
Snyp30-Nov-03 7:08 
GeneralRe: Help with going through text file. Pin
BaldwinMartin30-Nov-03 19:48
BaldwinMartin30-Nov-03 19:48 
QuestionMFC multiple documents? Pin
IndrekSnt29-Nov-03 3:16
IndrekSnt29-Nov-03 3:16 
AnswerRe: MFC multiple documents? Pin
Anonymous29-Nov-03 5:21
Anonymous29-Nov-03 5:21 
GeneralRe: MFC multiple documents? Pin
IndrekSnt29-Nov-03 6:30
IndrekSnt29-Nov-03 6:30 
GeneralRe: MFC multiple documents? Pin
l a u r e n29-Nov-03 13:32
l a u r e n29-Nov-03 13:32 
AnswerRe: MFC multiple documents? Pin
JWood29-Nov-03 14:03
JWood29-Nov-03 14:03 
GeneralRe: MFC multiple documents? Pin
JWood29-Nov-03 15:03
JWood29-Nov-03 15:03 
GeneralRe: MFC multiple documents? Pin
IndrekSnt29-Nov-03 22:51
IndrekSnt29-Nov-03 22:51 
GeneralCryptVerifySign - how it work Pin
Alyan29-Nov-03 0:41
Alyan29-Nov-03 0:41 
Generalcrystal report ocx - HRESULT - 2147024770 Pin
murali_utr29-Nov-03 0:15
murali_utr29-Nov-03 0:15 
GeneralRe: crystal report ocx - HRESULT - 2147024770 Pin
Steve S30-Nov-03 23:46
Steve S30-Nov-03 23:46 
GeneralNeed one more help Pin
murali_utr3-Dec-03 21:35
murali_utr3-Dec-03 21:35 

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.