4
$\begingroup$

Which one is better approach do data compression before encrypting it or Encrypt data before compression ? I think it is biased towards the application requirement. Please share your views.

$\endgroup$
7
$\begingroup$

Compressing encrypted data doesn't work. Encrypted data looks pseudorandom, therefore if you try to compress it, you'll find that the compression is ineffective.

Try it. You'll see. It's a very simple experiment -- give it a try.

$\endgroup$
4
$\begingroup$

Always compress first. The goal of encryption is to make data look random and it's impossible to compress random data. Therefore, if you succeed in significantly compressing encrypted data, you need to look for a new encryption algorithm.

If encrypted data doesn't look random, that's a big hint about how to decrypt it. For example, substitution cyphers fail because (assuming the plaintext is ordinary English prose and it's reasonably long) the most common character is almost certain to be the code for E. The next most common characters are almost certain to be the codes for T, A, O and so on.

$\endgroup$
2
$\begingroup$

As well as the other comments, I should point out that the converse is also true.

Encrypted data should be incompressible, and hence will be ineffective. However, compressing data before encryption can also make the encryption more secure.

Suppose your plaintext is plain text with a known structure (e.g. MIME, XML, JSON), for example. If an attacker knows that this is what is being encrypted, then it's extremely likely that there are blocks of your plaintext which are known to an attacker. Your cryptosystem is, therefore, vulnerable to a known-plaintext attack. Compressing first makes your "plaintext" look more like random data. If it didn't look like random data, then you could compress it further.

(Of course, this doesn't actually save your cryptosystem from this kind of attack, but it can never make it more vulnerable given a proper compression scheme. There are many techniques in modern cryptography where it can't formally be shown that they help security, but it can be shown that they can't hurt. This is one of them.)

In addition, there may be performance advantages. Many modern compression algorithms are faster than modern ciphers, using typical implementations on typical hardware. Compressing first means that there's less data to encrypt. On long messages, this can be a worthwhile tradeoff.

So yes, compress before encrypting.

$\endgroup$
  • $\begingroup$ Compression can also introduce security problems; see CRIME. It's not true that compression can never make you more vulnerable; CRIME shows that compression can make you more vulnerable, and it's quite realistic for it to happen in practice. $\endgroup$ – D.W. Mar 11 '14 at 2:16
  • $\begingroup$ Yes, just to make things clear, I was referring to a known plaintext attack. Plaintext injection attacks (which CRIME relies on) are another attack vector which should certainly be kept in mind if they are relevant. $\endgroup$ – Pseudonym Mar 11 '14 at 6:47
  • $\begingroup$ Actually, compression can also introduce security problems even under a known-plaintext attack model (even if chosen plaintext attacks are not practical), because to the length side channel. Moreover, in practice chosen-plaintext attacks are often a realistic threat (as also illustrated by CRIME). Bottom line: your statements in your answer are not accurate and could lend the wrong impression. $\endgroup$ – D.W. Mar 11 '14 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.