cornerhost wiki   GnuPrivacyGuard UserPreferences
 
HelpContents FindPage Diffs Info Edit Subscribe XML Print View

GnuPrivacyGuard (GnuPG) is [WWW]GNU Privacy Guard. It's a free replacement for PGP, which is a standard tool for public key encryption.

There's a good [WWW]quick overview at kuro5hin

... And the official [WWW]mini-howto

Quickly generate a key:

% gpg --gen-key

and to list/export:

% gpg --list-keys
% gpg -a --export address@wherever.com

to trust a key after "gpg: There is no indication that this key really belongs to the owner" error:

gpg --edit-key other@person.com trust
# or gpg --sign-key other@person.com # if you have your own key to sign it with (I didn't)

The [WWW]GnuPGInterface for python may come in handy. This class makes it even easier to use:

import GnuPGInterface

class GnuPG(GnuPGInterface.GnuPG):
    def __init__(self):
        GnuPGInterface.GnuPG.__init__(self)
        self.setup_my_options()

    def setup_my_options(self):
        self.options.armor = 1
        self.options.meta_interactive = 0
        self.options.extra_args.append('--no-secmem-warning')

    def encrypt_string(self, string, recipients):
        self.options.recipients = recipients   # a list!
        proc = self.run(['--encrypt'], create_fhs=['stdin', 'stdout'])
        proc.handles['stdin'].write(string)
        proc.handles['stdin'].close()
        output = proc.handles['stdout'].read()
        proc.handles['stdout'].close()
        proc.wait()
        return output


    def decrypt_string(self, ciphertext, passphrase):
        self.passphrase = passphrase
        p = self.run(['--decrypt', "--quiet"],
                     create_fhs=['stdin','stdout','stderr'])
        p.handles['stdin'].write(ciphertext)
        p.handles['stdin'].close()
        res = p.handles['stdout'].read()
        p.handles['stderr'].close()
        p.handles['stdout'].close()
        p.wait()
        self.passphrase = None
        return res


PythonPowered