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

 

Encrypting a stream

 


 

Working with ECL streams, you have a simple way to encrypt a stream data.

 

Encrypting a stream

There are two ways to encrypt a stream data:

  1. To pass not blank Password parameter to the constructor of the newly created stream. The CompressionLevel parameter must be not equal to eclNone.
  2. To specify Password property of already created compressed stream and to set the value of Encrypted property to True. The value of CompressionLevel property must be not equal to eclNone. Note: This variant is not valid for TECLStream.
  3.  

    First way could be used when:

    • 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

      { 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;

       

      { open compressed and encrypted file }

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

      { switch off an encryption }

      CompFS.Encrypted := False;

      { close compressed and decrypted file }

      CompFS.Free;

      end;

       

        © 2003 - 2017 ComponentAce  | .net zip component | barcode for .net | delphi zip component | delphi database Oct 19, 2017