-
Creating a new encrypted file
-
Creating a new memory stream
-
Creating a new TECLStream
Second variant could be used to:
-
Encrypt already open existing file (TECLFileStream)
-
Encrypt already created memory stream (TECLMemoryStream)
Opening an encrypted stream
To access an encrypted data through the ECL stream (TECLFileStream or TECLStream) you should pass proper Password parameter to a stream constructor.
If the value of Password parameter is wrong, an exception is raised.
Accessing encrypted stream data
Once you created ECL stream object with the right password, you may don't care about the encryption. ECL streams encrypt and decrypt the stream data on the fly.
Decrypting a stream
To decrypt data of already created TECLFileStream or TECLMemoryStream (with the right Password) you should set Encrypted property of ECL stream to False.
See also Encrypting a file, Getting encryption state of a file topics.
The following example illustrates how to encrypt and compress and then decrypt and decompress a file.
Example:
var
CompFS: TECLFileStream;
begin
CompFS := TECLFileStream.Create('c:\test_comp.ecl', fmCreate, 'Password', zlibFastest);
CompFS.LoadFromFile('c:\test.txt');
ShowMessage('Size of compressed and encrypted file: '+IntToStr(CompFS.PackedSize));
CompFS.Free;
CompFS := TECLFileStream.Create('c:\test_comp.ecl', fmOpenReadWrite or fmShareDenyNone, 'Password');
CompFS.Encrypted := False;
CompFS.Free;
end;