randydom
randydom

Reputation: 405

Compress and encrypt in Delphi

I need a fast and strong compression + encryption method for my DAT file.

I've a DAT file which contains very sensitive information and I would like to compress and encrypt it. I know I can use Zlib in compression method but how about the encryption method too ?

many thanks

Upvotes: 1

Views: 4242

Answers (3)

Arnaud Bouchez
Arnaud Bouchez

Reputation: 43023

If you need both encryption and compression at the same time, you have two ways of implementing it:

  • Use your data in a memory buffer, then compress this buffer, then encrypt it;
  • Use streams, one for compression, the other for encryption.

In all cases, the best is to compress before encryption. It is more difficult to uncypher data from a compressed format, since its content is less expectable.

Then rely on a strong enough encryption algorithm (like AES).

You have all those features in our Open Source units (from Delphi 5 up to XE2). You can use ZIP, or try our much faster (but less efficient in term of compression ration) SynLZ. Then SynCrypto can be used to encrypt it. There are direct functions handling RawByteString kind of data, which contents the data in a memory buffer.

Upvotes: 4

Marco van de Voort
Marco van de Voort

Reputation: 26358

Another much used component is DCPCrypt:

http://www.cityinthesky.co.uk/opensource/dcpcrypt

It is stream based, so you can layer compression and encryption. I don't know code that does it in one step. (at least not with sensible encryption)

Upvotes: 6

whosrdaddy
whosrdaddy

Reputation: 11860

Please check out the Delphi Encryption Compendium (aka DEC):

Upvotes: 6

Related Questions