RichViewEdit and Streams
Posted: Fri Sep 22, 2006 12:05 am
Hi,
I am trying to Encrypt and Decrypt RTF in a TMemoryStream using TRichViewEdit but I am having major problems with it. To Encrypt/Decrypt I'm using the DCPcrypt latest versions the Encryption Component I'm using is TDCP_rc4
I Encrypt the RTF like this:
procedure TForm1.Button1Click(Sender: TObject);//Encrypt
var
Password: string;
source,Dest: TMemoryStream;
begin
Password := '3FB86FD0FE30BA119033447D0CF16CE4';
Source := TMemoryStream.Create;
Dest := TMemoryStream.Create;
Source.Seek(0,soFromBeginning);
Dest.Seek(0,soFromBeginning);
RichViewEdit1.SaveRTFToStream(Source,false);
Source.Seek(0,soFromBeginning);
RichViewEdit1.Clear;
Cipher.InitStr(Password,TDCP_sha512);
Cipher.EncryptStream(Source,Dest,Source.Size);
Dest.Seek(0,soFromBeginning);
RichViewEdit1.LoadRTFFromStream(Dest);
RichViewEdit1.Format;
Source.Free;
Dest.Free;
Cipher.Burn;
end;
and Decrypt like this:
procedure TForm1.Button2Click(Sender: TObject);//Decrypt
var
Password: string;
source,Dest: TMemoryStream;
begin
Password := '3FB86FD0FE30BA119033447D0CF16CE4';
Source := TMemoryStream.Create;
Dest := TMemoryStream.Create;
Source.Seek(0,soFromBeginning);
Dest.Seek(0,soFromBeginning);
RichViewEdit1.SaveRVFToStream(Source,false);
Source.Seek(0,soFromBeginning);
RichViewEdit1.Clear;
Cipher.InitStr(Password,TDCP_sha512);
Cipher.DecryptStream(Source,Dest,Source.Size);
Dest.Seek(0,soFromBeginning);
RichViewEdit1.LoadRTFFromStream(Dest);
RichViewEdit1.Format;
Source.Free;
Dest.Free;
Cipher.Burn;
end;
The problem I'm getting is the DecryptStream part, it just formats jumbled up characters instead of Decrypting it from the Stream, is this something I'm doing wrong in the Decryption part or should I be doing something else with TRichViewEdit?
Is it because TRichViewEdit cannot display some Characters that are encrypted? I have tried using LoadRVFFromStream but I always get nothing as if there isn't even anything in the Stream
Please if anyone knows what is wrong, please help, I have been tearing my hair out with it for days!!
many thanks
Chris
I am trying to Encrypt and Decrypt RTF in a TMemoryStream using TRichViewEdit but I am having major problems with it. To Encrypt/Decrypt I'm using the DCPcrypt latest versions the Encryption Component I'm using is TDCP_rc4
I Encrypt the RTF like this:
procedure TForm1.Button1Click(Sender: TObject);//Encrypt
var
Password: string;
source,Dest: TMemoryStream;
begin
Password := '3FB86FD0FE30BA119033447D0CF16CE4';
Source := TMemoryStream.Create;
Dest := TMemoryStream.Create;
Source.Seek(0,soFromBeginning);
Dest.Seek(0,soFromBeginning);
RichViewEdit1.SaveRTFToStream(Source,false);
Source.Seek(0,soFromBeginning);
RichViewEdit1.Clear;
Cipher.InitStr(Password,TDCP_sha512);
Cipher.EncryptStream(Source,Dest,Source.Size);
Dest.Seek(0,soFromBeginning);
RichViewEdit1.LoadRTFFromStream(Dest);
RichViewEdit1.Format;
Source.Free;
Dest.Free;
Cipher.Burn;
end;
and Decrypt like this:
procedure TForm1.Button2Click(Sender: TObject);//Decrypt
var
Password: string;
source,Dest: TMemoryStream;
begin
Password := '3FB86FD0FE30BA119033447D0CF16CE4';
Source := TMemoryStream.Create;
Dest := TMemoryStream.Create;
Source.Seek(0,soFromBeginning);
Dest.Seek(0,soFromBeginning);
RichViewEdit1.SaveRVFToStream(Source,false);
Source.Seek(0,soFromBeginning);
RichViewEdit1.Clear;
Cipher.InitStr(Password,TDCP_sha512);
Cipher.DecryptStream(Source,Dest,Source.Size);
Dest.Seek(0,soFromBeginning);
RichViewEdit1.LoadRTFFromStream(Dest);
RichViewEdit1.Format;
Source.Free;
Dest.Free;
Cipher.Burn;
end;
The problem I'm getting is the DecryptStream part, it just formats jumbled up characters instead of Decrypting it from the Stream, is this something I'm doing wrong in the Decryption part or should I be doing something else with TRichViewEdit?
Is it because TRichViewEdit cannot display some Characters that are encrypted? I have tried using LoadRVFFromStream but I always get nothing as if there isn't even anything in the Stream
Please if anyone knows what is wrong, please help, I have been tearing my hair out with it for days!!
many thanks
Chris