When compressing and encrypting, should I compress first, or encrypt first?
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? 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. maxbublis Compression before encryption is surely more space efficient but in the same time less secure. That's why I would disagree with other answers. Most compression