Encryption on a compressed file

Can I do encryption on a compressed file and again decompress the file after decryption to get the original data?

• What are your thoughts? What makes you think you wouldn't be able to? Why are you unsure? – D.W. Jan 9 '16 at 22:08

Can i do encryption on a compressed file and again decompress the file after decryption to get the original data?

If the compression and decompression algorithms are lossless then yes.

If you are wondering about it, an example of a lossy compression system is the JPEG encoding process. The lost data is generally visually insignificant, but enables much better compression ratios. However strictly speaking an image encoded with JPEG will not produce exactly the same image after decompression.

Compression systems like zip, gzip and bzip use lossless compression.

Also note that compression is normally applied before encryption because encryption produces data that is essentially impossible to compress.