Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When compressing and encrypting, should I compress first, or encrypt first? [closed]

If I were to AES-encrypt a file, and then ZLIB-compress it, would the compression be less efficient than if I first compressed and then encrypted?

In other words, should I compress first or encrypt first, or does it matter?

like image 432
seisatsu Avatar asked Jan 13 '11 02:01

seisatsu


People also ask

Should you encrypt first and then compress or compress first and then encrypt Why?

You should compress before encrypting. Encryption turns your data into high-entropy data, usually indistinguishable from a random stream. Compression relies on patterns in order to gain any size reduction.

What is the correct order of data encryption?

First compress and then encrypt is best. However there is more to good encryption than just the order of encrypt and compress. Ideally you should use non-deterministic authenticated encryption. - encryption should take some random as input (next to a sectret key) so that it produces a different ciphertext every time.

Can we use both compression and encryption at the same time?

Once encrypted no other than the intended receiver can decrypt it. Hence compression and encryption is done simultaneously.

Why should you compress before encrypting?

Compress and then encrypt is better. Data compression removes redundant character strings in a file. So the compressed file has a more uniform distribution of characters. This also provides shorter plaintext and ciphertext, which reduces the time spent encrypting, decrypting and transmiting the file.


1 Answers

Compress first. Once you encrypt the file you will generate a stream of random data, which will be not be compressible. The compression process depends on finding compressible patterns in the data.

like image 161
Ferruccio Avatar answered Oct 22 '22 23:10

Ferruccio