Created
July 19, 2012 19:56
-
-
Save abeluck/3146378 to your computer and use it in GitHub Desktop.
Python + gpgme snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gpgme | |
# Loop through all keys in the default keyring | |
# Print the key id, the first uid, and all subkeys | |
# open context, defaults to ~/.gnupg afaik | |
ctx = gpgme.Context() | |
for key in ctx.keylist(): | |
# looks like subkeys[0] is the master key | |
print "Key: %s %s" % (key.subkeys[0].keyid, key.uids[0].uid) | |
# loop through subkeys, start at 1 because 0 is master key | |
for idx in range(1, len(key.subkeys)): | |
print "\tSubkey: %s" % ( key.subkeys[idx].keyid ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gpgme | |
import os | |
# Set the 'homedir' that gpg reads the keyring from | |
os.environ['GNUPGHOME'] = '/path/to/some/directory/' # supports relative paths too | |
ctx = gpgme.Context() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment