Search code examples
encryptiongnupg

How do I list information for a GnuPG encrypted message?


I'm still working with GPG, as in this post: How do I encrypt plaintext with GnuPG?

What I need now is to be able to list various info (e.g. all recipients) of an encrypted message without necessarily decrypting it. I've seen links to different commands like --list-only, but nothing seems to work.

--list-only will display all keys but your own (if it was encrypted to you). Basically I need to be able to determine if the item was encrypted to me, so as to "file" it or take other action.

Does anyone have an authoritative reference (or any input really) on this?


Solution

  • In order to see all keys (that are not hidden) that a block of encrypted data was encrypted to—including your own—you could simply make your secret-keyring unavailable, via something like this:

    gpg --no-default-keyring --secret-keyring /dev/null -a --list-only
    

    That tells GPG to not use any default keyrings (--no-default-keyring) if an invalid/missing keyring is specified, and then goes on to specify an invalid/missing secret-keyring (--secret-keyring /dev/null).