'>>> g = GnuPG(None)
>>> g.encrypt("Hello, World", to=["smari@mailpile.is"])[0]
0'

def encrypt(self, data, tokeys=[], armor=True, sign=False, fromkey=None, throw_keyids=False):

    if tokeys:
        action = ['--encrypt', '--yes', '--expert', '--trust-model', 'always']
        for r in tokeys:
            action.append('--recipient')
            action.append(r)
        action.extend([])
        self.event.running_gpg((_('Encrypting    %d    bytes    of    data    to    %s') % (len(data), ',    '.join(tokeys))))
    else:
        action = ['--symmetric', '--yes', '--expert']
        self.event.running_gpg((_('Encrypting    %d    bytes    of    data    with    password') % len(data)))
    if armor:
        action.append('--armor')
    if sign:
        action.append('--sign')
    if (sign and fromkey):
        action.append('--local-user')
        action.append(fromkey)
    if throw_keyids:
        action.append('--throw-keyids')
    if fromkey:
        self.prepare_passphrase(fromkey, signing=True)
    retvals = self.run(action, gpg_input=data, send_passphrase=(sign or (not tokeys)))
    return (retvals[0], ''.join(retvals[1]['stdout']))
