 <p>Finally resolved the issue. The program is handling everything correctly.</p> <p>On the sending side:</p> <pre><code>compression: gzip -c secret.txt -9 &gt; compressed.txt.gz encryption: openssl enc -aes-256-cbc -a -salt -in compressed.txt.gz -out encrypted.txt </code></pre> <p>The compression output (gz) is given as an input for encryption which outputs a text file. The resulting output is purely ascii.</p> <p>On the receiving side:</p> <pre><code>decryption: openssl enc -d -aes-256-cbc -a -in decryptme.txt -out decrypted.txt.gz decompression: gunzip -c decrypted.txt.gz &gt; message.txt </code></pre>