Is it better to encrypt a message and then compress it or the other way around? Which provides more security?

前端 未结 9 1276
离开以前
离开以前 2020-12-09 02:33

I have the assumption there is no added protection at all.

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-09 02:52

    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. Since encryption destroys such patterns, the compression algorithm would be unable to give you much (if any) reduction in size if you apply it to encrypted data. If the encryption is done properly then the result is basically random data. Most compression schemes work by finding patterns in your data that can be in some way factored out.

    Compression before encryption also slightly increases your practical resistance against differential cryptanalysis (and certain other attacks) if the attacker can only control the uncompressed plaintext, since the resulting output may be difficult to deduce.

提交回复
热议问题