-1

I have a 85mb tar.gz file. When I encrypt this using gpg the encrypted file size is 85 mb.

When trying to encrypt using Python gnupg encrypted file size is 115 mb. That is very strange since gnupg just uses sub process to gpg to send arguments. Still there is big difference in file size. Tried in Linux and win7. What might the problem be?

Python 2.7.3 on linux gnupg 0.3.6

codes below

gpg -c --cipher-algo AES256 temp.tar.gz <<< command line code.
with open(outputfolder+tarname, 'rb') as f:     
        status = gpg.encrypt_file(f, recipients=None, symmetric="AES256", output=outputfolder+tarname+'.gpg', passphrase='pass')
vas
  • 27
  • 1
  • 7

1 Answers1

1

By default the encrypted file is created with ASCII armored, not binary, output. Take a look at the first few lines of the file produced:

-----BEGIN PGP MESSAGE-----
Version: GnuPG v1

jA0ECQMCeWOyFPPGpLVg0u0Br8cioBHzZB38LC5o14PS1I2MZsxNPwVM2tnjsd41
FXz0m28S7LERQ2Cld3Ud7tRCgcVtRtGwKCdgDHZRWDr2S7wNHgTlvBU91In8+HF9
....

Binary output can be generated by supplying armor=False to encrypt_file():

with open(outputfolder+tarname, 'rb') as f:     
        status = gpg.encrypt_file(f, recipients=None, symmetric="AES256", output=outputfolder+tarname+'.gpg', passphrase='pass', armor=False)

Now the output should be binary and the file size should be much closer to that of the original file.

Reference: http://pythonhosted.org/python-gnupg/#encryption

MTietze
  • 43
  • 4
mhawke
  • 84,695
  • 9
  • 117
  • 138