Encrypting a file
EasyCompression Library provides a file stream interface with TECLFileStream class that can be easily used to compress/encrypt and decompress/decrypt a file.
Encrypting a file.
To encrypt a file to file you need to perform the following 3 steps:
-
Create an instance of TECLFileStream for the destination encrypted file with not blank Password and with CompressionLevel parameter not equal to eclNone value, i.e. with one of the compression modes.
-
Call LoadFromFile method of TECLFileStream to load, compress and encrypt source file.
-
Free the TECLFileStream object to close encrypted file.
Example:
var
CompFS: TECLFileStream;
begin
CompFS := TECLFileStream.Create('c:\test_comp.ecl', fmCreate, 'password', zlibFastest);
CompFS.LoadFromFile('c:\test.txt');
CompFS.Free;
end;
Decrypting a file.
To decrypt and decompress a file to file you need to perform the following 3 steps:
-
Create an instance of TECLFileStream for the source encrypted and compressed file with two parameters in constructor: FileName and Mode.
-
Call SaveToFile method of TECLFileStream to decrypt and decompress data and save to the destination file.
-
Free the TECLFileStream object to close encrypted file.
Example:
var
CompFS: TECLFileStream;
begin
CompFS := TECLFileStream.Create('c:\test_comp.ecl', fmOpenRead or fmShareDenyNone, 'password');
CompFS.SaveToFile('c:\test_decomp.txt');
CompFS.Free;
end;
|