Article View: borland.public.cppbuilder.nativeapi
Article #8121Encrypting/Decrypting stringlist
From: roger
Date: Tue, 23 Nov 2004 18:09
Date: Tue, 23 Nov 2004 18:09
57 lines
3073 bytes
3073 bytes
Can someone please tell me why the following code would return partially
correct data...it seems if i am not freeing up some buffer or freeing up
where is shouldn't..if i use the same code for a single string its fine.
void __fastcall TForm1::CryptStringList(TStrings *stringsin,TStrings
*stringsout,AnsiString thekey)
{
DWORD dwDataLen = 0;
DWORD dwEncLen =0;
LPSTR szData =0;
stringsout->BeginUpdate();
CMyCrypto myCrypto((LPSTR)thekey.c_str(), CALG_RC4);
for(int a=0;a<stringsin->Count;a++)
{
dwDataLen = stringsin->Strings[a].Length();
dwEncLen = dwDataLen;
dwDataLen = stringsin->Strings[a].Length();
szData = new CHAR[dwEncLen + 1];
strcpy(szData, stringsin->Strings[a].c_str());
szData[dwEncLen] = 0;
if (bEncrypt) {
if (myCrypto.Encrypt((BYTE*)szData,&dwDataLen,dwDataLen,true))
stringsout->Add(StrPas(szData));
} else {
if (myCrypto.Decrypt((BYTE*)szData,&dwDataLen, true))
stringsout->Add(StrPas(szData));
}
szData = NULL;
}/// for next loop
stringsout->EndUpdate();
delete[] szData;
}
///////////////////////////
bool CMyCrypto::Encrypt(LPBYTE pData, LPDWORD pdwDataSize,DWORD
dwBufferSize,bool bFinal)
{
return CryptEncrypt(m_hKey, // encryption key handle
0, // optional hash handle
bFinal, // true if last block
0, // flag (reserved)
pData, // data to encrypt
pdwDataSize, // data size (in bytes)
dwBufferSize); // buffer size (in bytes)
}
//---------------------------------------------------------------
bool CMyCrypto::Decrypt(LPBYTE pData, LPDWORD pdwDataSize,bool bFinal)
{
return CryptDecrypt(m_hKey, // encryption key handle
0, // optional hash handle
bFinal, // true if last block
0, // flag (reserved)
pData, // data to encrypt
pdwDataSize); // data size (in bytes)
}
Technical Details
Message-ID:
<41a37ce2$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!news.zanker.org!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,8141b40d2daa221d,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "roger" <rogersmail@ntlworld.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Encrypting/Decrypting stringlist Date: Tue, 23 Nov 2004 18:09:56 -0000 Lines: 59 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2739.300 NNTP-Posting-Host: 81.103.69.122 Message-ID: <41a37ce2$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1101233378 81.103.69.122 (23 Nov 2004 10:09:38 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!news.zanker.org!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail