5

I'm encrypting a file using the python-gnupg module like this. Ultimately, I want to use the AES256 cipher for encryption:

status = gpg.encrypt_file(fin, recipients=['root@frarakee'], output='foo.bin.gpg')

When I check the file at the CLI, it tells me it's a PGP message:

# file foo.bin.gpg 
foo.bin.gpg: PGP message

If I encrypt the file using gpg at the CLI (Ubuntu 14.04), the file command tells me its data yet gpg shows it's using AES256:

# gpg --verbose -r root@frarakee --cipher-algo AES256 -e foo.bin
gpg: using PGP trust model
gpg: using subkey 1C32653F instead of primary key A7173E08
gpg: This key belongs to us
gpg: reading from `foo.bin'
File `foo.bin.gpg' exists. Overwrite? (y/N) y
gpg: writing to `foo.bin.gpg'
gpg: RSA/AES256 encrypted for: "132653F root@frarakee <root@frarakee>"

# file foo.bin
foo.bin: data

Notably, the python docs state:

The default cipher_algo, if unspecified, is 'AES256'

But the file command only seems to agree with this when I used symmetric encryption:

# gpg --cipher-algo AES256 -c /tmp/foo.bin
# file /tmp/foo.bin.gpg 
foo.bin.gpg: GPG symmetrically encrypted data (AES256 cipher)

I'm not sure if this is a bug in the file magic, the python-gpg module, or just my understanding. How can I tell what cipher is actually being used by gpg or the python-gpg module? Is there a better place to ask this?

1

file only looks for some magic bytes to determine the file type, but does not fully parse the OpenPGP packets. You can view all encryption details by running gpg --list-packets or pgpdump (output is easier to read, but needs to be installed separately). Reading through RFC 4880, OpenPGP might help at understanding the very technical output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.