How to check if a GPG encrypted file is encrypted using a specific public key

encryptiongnupgpublic-keypublic-key-encryptionSecurity

Consider if a file is encrypted using command

e.g.

gpg --output test.txt.gpg --encrypt --recipient test@example.com test.txt

Now, consider another person received test.txt.gpg the the pub key test@example.com, how to perform a check to make sure the file is really encrypted using the pub key?

Best Answer

Some behavior has changed in newer versions of gpg (I'm testing on gpg v2.2.4). It prompts you for the passphrase when doing --list-packets. And now by default, -k doesn't show the key IDs anymore, only the 40-char fingerprints.

Here are some commands that will skip prompts and show the key IDs:

# show public key ID that it was encrypted with, skipping prompts
gpg --pinentry-mode cancel --list-packets file.gpg

# list keys with the key IDs
gpg -k --keyid-format long

You can then match the 16-character key ID from --list-packets to list from -k.

Related Question