🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8123

Re: Encrypting/Decrypting stringlist

#8123
From: roger
Date: Tue, 23 Nov 2004 19:33
111 lines
4411 bytes
It seems to work fine except it trips up and stops when it encounters the
third line in the stringlist which is:
::.. Text here ..:: and here:

does it have anything to do with the colons and dots.


"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:41a385b5$1@newsgroups.borland.com...
>
> "roger" <rogersmail@ntlworld.com> wrote in message
> news:41a37ce2$1@newsgroups.borland.com...
>
>
> >     dwDataLen = stringsin->Strings[a].Length();
> >     dwEncLen = dwDataLen;
> >     dwDataLen = stringsin->Strings[a].Length();
>
> The second assignment to dwDataLen is redundant.  It already has the value
> of Length().
>
> >     szData = new CHAR[dwEncLen + 1];
>
> You are allocating a buffer...
>
> >      szData = NULL;
>
> Yet you are then nullifying the pointer withoug actually freeing it.
>
> >      delete[] szData;
>
> szData is NULL by this point.
>
> >     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));
> >              }
>
> You don't need to use StrPas().  It is an obsolete function.  Just pass
the
> char* pointer directly, it will be converted to AnsiString automatically
for
> you:
>
>     stringsout->Add(szData);
>
> Also, for your encryption, what does the actual encrypted data look like?
> Are there are '\0' characters in it?  There most likely is.  That would
> account for the incomplete data being passed back to the TStringList,
since
> you are not taking '\0' characters into account at all.
>
> Try this code instead (untested):
>
>     void __fastcall TForm1::CryptStringList(TStrings* stringsin, TStrings*
> stringsout, const AnsiString &thekey)
>     {
>         DWORD dwDataLen, dwEncLen;
>         AnsiString asData;
>         bool bOk;
>         CMyCrypto myCrypto(thekey.c_str(), CALG_RC4);
>
>         stringsout->BeginUpdate();
>         try
>         {
>             for(int a = 0; a < stringsin->Count; ++a)
>             {
>                 dwDataLen = stringsin->Strings[a].Length();
>                 dwEncLen = dwDataLen;
>
>                 bOk = !bEncrypt;
>                 if( !bOk )
>                     bOk = myCrypto.Encrypt(NULL, &dwEncLen, 0, true);
>
>                 if( bOk )
>                 {
>                     if( dwEncLen < dwDataLen )
>                         asData.SetLength(dwDataLen);
>                     else
>                         asData.SetLength(dwEncLen);
>
>                     strncpy(asData.c_str(), stringsin->Strings[a].c_str(),
> dwDataLen);
>
>                     if( bEncrypt )
>                         bOk = myCrypto.Encrypt((BYTE*)szData.c_str(),
> &dwDataLen, asData.Length(), true);
>                     else
>                         bOk = myCrypto.Decrypt((BYTE*)szData.c_str(),
> &dwDataLen, true);
>
>                     if( bOk )
>                     {
>                         asData.SetLength(dwDataLen);
>                         stringsout->Add(asData);
>                     }
>                 }
>             }
>         }
>         __finally {
>             stringsout->EndUpdate();
>         }
>     }
>
>
> Gambit
>
>
Technical Details
Message-ID: <41a3907d@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsgate.cistron.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!lnewsoutpeer01.lnd.ops.eu.uu.net!lnewsinpeer01.lnd.ops.eu.uu.net!emea.uu.net!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <41a37ce2$1@newsgroups.borland.com> <41a385b5$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,8141b40d2daa221d
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "roger" <rogersmail@ntlworld.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <41a37ce2$1@newsgroups.borland.com> <41a385b5$1@newsgroups.borland.com>
Subject: Re: Encrypting/Decrypting stringlist
Date: Tue, 23 Nov 2004 19:33:35 -0000
Lines: 113
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: <41a3907d@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1101238397 81.103.69.122 (23 Nov 2004 11:33:17 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsgate.cistron.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!lnewsoutpeer01.lnd.ops.eu.uu.net!lnewsinpeer01.lnd.ops.eu.uu.net!emea.uu.net!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail