RTC Forums
May 02, 2024, 06:06:04 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: encryption  (Read 3366 times)
Ronald van Tour
RTC License++
*****
Posts: 37


« 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;
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 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
Logged
Ronald van Tour
RTC License++
*****
Posts: 37


« Reply #2 on: October 31, 2013, 09:29:12 AM »

Thank you.

My version of RTC needs the ansistring as input.
But it works!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.023 seconds with 17 queries.