RTC Forums

Subscription => Support => Topic started by: Ronald van Tour on October 30, 2013, 04:00:06 PM



Title: encryption
Post by: Ronald van Tour on October 30, 2013, 04:00:06 PM
I have a memo and 2 buttons and below code.
When I decrypt I get not all data back. Only a few lines.



procedure TForm2.Button1Click(Sender: TObject);
var A:ansistring;
begin
  A:=(memo1.lines.Text);
  Crypt(A,'12994');
  memo1.Text:=(A);
end;

procedure TForm2.Button2Click(Sender: TObject);
var A:ansistring;
begin
  A:=(memo1.lines.Text);
  DeCrypt(A,'12994');
  memo1.Text:=(A);
end;


Title: Re: encryption
Post by: D.Tkalcec (RTC) on October 30, 2013, 04:48:23 PM
TMemo component from Delphi does NOT have the capability for storing binary content. It is only for Text. Once you use Crypt, you will no longer have pure Text. You will have binary content. Also, when using Delphi 2009 and later, TMemo can contain Unicode characters, which need to be encoded to 8-bit characters before they can be passed to the Crypt function, and decoded back to Unicode after using Decrypt.

For example, like this:

uses rtcInfo,rtcCrypt;

procedure TForm2.Button1Click(Sender: TObject);
var A:RtcString;
begin
  A:=Utf8Encode(memo1.lines.Text);
  Crypt(A,'12994');
  Write_File('crypt.txt',A);
end;

procedure TForm2.Button2Click(Sender: TObject);
var A:RtcString;
begin
  A:=Read_File('crypt.txt');
  DeCrypt(A,'12994');
  memo1.Text:=Utf8Decode(A);
end;

Best Regards,
Danijel Tkalcec


Title: Re: encryption
Post by: Ronald van Tour on October 31, 2013, 09:29:12 AM
Thank you.

My version of RTC needs the ansistring as input.
But it works!