Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.pascal.delphi.misc > #328
| From | bok <bok.globule@gmail.com> |
|---|---|
| Newsgroups | comp.lang.pascal.delphi.misc |
| Subject | Works in D6 not in XE2... any help is appreciated |
| Date | 2012-06-15 21:49 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <6be86aa5-a63a-4c4e-9c7a-eee5bded75c7@googlegroups.com> (permalink) |
The following works fine in D6+Win7 but I get "Invalid buffer size for decryption" error under XE2+Win7 during decrypion(button2Click). A mozillla liscensed unit from 2001 that does the actual AES operations is raising that error, but I hesitate to include that unit here as it is hundreds of lines long,
but TAESKey128 = array [0..15] of byte is in the TYPE statement there.
I'm guessing that the problem is either a change in the "Size" "fillchar" pointer "^" or "move" operations between D6 and XE2 or the fact that I'm running a 64bit OS (Windows was 16 bit in 2001)
=======================================================================
function StringToHex(S: string): string; // Convert all characters to hex
var i: integer;
begin
Result := '';
for i := 1 to Length( S ) do Result := Result + IntToHex( Ord( S[i] ), 2 );
end;
function HexToString(S: string): string;
var i: integer;
begin
Result := '';
for i := 1 to Length( S ) do
if ((i mod 2) = 1) then
Result := Result + Chr( StrToInt( '0x' + Copy( S, i, 2 )));
end;
procedure TForm1.Button1Click(Sender: TObject);// Encryption
var
Source: TStringStream;
Dest: TStringStream;
Size: integer;
Key: TAESKey128;
begin
Source := TStringStream.Create( Memo1.Text );
Dest := TStringStream.Create( '' );
try
Size := Source.Size;
Dest.WriteBuffer( Size, SizeOf(Size) );
FillChar( Key, SizeOf(Key), 0 ); // Prepare key
Move( PChar(edit1.Text)^, Key, Min( SizeOf( Key ), Length( edit1.Text )));
EncryptAESStreamECB( Source, 0, Key, Dest );
Memo2.Text := StringToHex( Dest.DataString );
finally
Source.Free;
Dest.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Source: TStringStream;
Dest: TStringStream;
Size: integer;
Key: TAESKey128;
begin
Source := TStringStream.Create( HexToString( Memo2.Text ));
Dest := TStringStream.Create( '' );
try
Size := Source.Size;
Source.ReadBuffer(Size, SizeOf(Size));
FillChar(Key, SizeOf(Key), 0);
Move(PChar(edit1.Text)^, Key, Min(SizeOf(Key), Length(edit1.Text)));
DecryptAESStreamECB(Source, Source.Size - Source.Position, Key,Dest);
Memo1.Text := Dest.DataString;
finally
Source.Free;
Dest.Free;
end;
end;
Thanks for your help
DBM
Back to comp.lang.pascal.delphi.misc | Previous | Next — Next in thread | Find similar | Unroll thread
Works in D6 not in XE2... any help is appreciated bok <bok.globule@gmail.com> - 2012-06-15 21:49 -0700
Re: Works in D6 not in XE2... any help is appreciated "Maarten Wiltink" <maarten@kittensandcats.net> - 2012-06-16 07:30 +0200
Re: Works in D6 not in XE2... any help is appreciated bok <bok.globule@gmail.com> - 2012-06-16 00:09 -0700
Re: Works in D6 not in XE2... any help is appreciated "S.G" <S.G@none.special.ch> - 2012-06-16 12:01 +0300
Re: Works in D6 not in XE2... any help is appreciated JJ <jaejunks_at@_googlemail_dot._com> - 2012-06-16 15:39 +0000
Re: Works in D6 not in XE2... any help is appreciated "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2012-06-16 17:58 +0200
Re: Works in D6 not in XE2... any help is appreciated Marco van de Voort <marcov@toad.stack.nl> - 2012-06-16 18:37 +0000
Re: Works in D6 not in XE2... any help is appreciated "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2012-06-17 05:37 +0200
Re: Works in D6 not in XE2... any help is appreciated "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2012-06-16 17:58 +0200
Re: Works in D6 not in XE2... any help is appreciated "Ph. B." <philippe_NO_SPAM_.boucault@voila.fr> - 2012-06-16 19:53 +0200
Re: Works in D6 not in XE2... any help is appreciated "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2012-06-17 05:38 +0200
Re: Works in D6 not in XE2... any help is appreciated JJ <jaejunks_at@_googlemail_dot._com> - 2012-06-17 04:48 +0000
Re: Works in D6 not in XE2... any help is appreciated bok <bok.globule@gmail.com> - 2012-06-18 02:48 -0700
Re: Works in D6 not in XE2... any help is appreciated "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2012-06-18 13:52 +0200
Re: Works in D6 not in XE2... any help is appreciated "Maarten Wiltink" <maarten@kittensandcats.net> - 2012-06-26 23:06 +0200
csiph-web