Getting encryption state of a file
To know whether the file is encrypted, use IsECLFileEncrypted function.
The following example illustrates how to check whether the file is encrypted and handle wrong password input.
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;
if (IsECLFileEncrypted('c:\test_comp.ecl')) then
begin
try
CompFS := TECLFileStream.Create('c:\test_comp.ecl', fmOpenReadWrite or fmShareDenyNone, 'Wrong Password');
except
ShowMessage('Attempt to open a file with wrong password is failed!');
end;
try
CompFS := TECLFileStream.Create('c:\test_comp.ecl', fmOpenReadWrite or fmShareDenyNone, 'Password');
except
ShowMessage('Cannot open file "c:\test_comp.ecl"');
end
end
else
CompFS := TECLFileStream.Create('c:\test_comp.ecl', fmOpenReadWrite or fmShareDenyNone);
CompFS.CompressionLevel := ppmMax;
CompFS.Free;
end;
|