Delphi Database, Delphi Components from ComponentAce
Products Download Order Contact us
/img/help/home.gif /img/help/prev.gif /img/help/next.gif

 

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

{ create compressed and encrypted file }

CompFS := TECLFileStream.Create('c:\test_comp.ecl', fmCreate, 'Password', zlibFastest);

{ load, compress and encrypt data from test.txt file}

CompFS.LoadFromFile('c:\test.txt');

{ show the size of compressed data }

ShowMessage('Size of compressed and encrypted file: '+IntToStr(CompFS.PackedSize));

{ close compressed and encrypted file }

CompFS.Free;

 

{ check if file encrypted}

if (IsECLFileEncrypted('c:\test_comp.ecl')) then

begin

{ try to open compressed and encrypted file with wrong password}

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 to open compressed and encrypted file with correct password}

try

CompFS := TECLFileStream.Create('c:\test_comp.ecl', fmOpenReadWrite or fmShareDenyNone, 'Password');

except

ShowMessage('Cannot open file "c:\test_comp.ecl"');

end

end

else

{ open file without password }

CompFS := TECLFileStream.Create('c:\test_comp.ecl', fmOpenReadWrite or fmShareDenyNone);

{ change compression level }

CompFS.CompressionLevel := ppmMax;

{ close compressed file }

CompFS.Free;

end;

 

        © 2003 - 2024 ComponentAce  | .net zip component | barcode for .net | delphi zip component | delphi database Mar 29, 2024