tags:

views:

273

answers:

3

I am using Pyme to interface with GPGME and have had no problems signing / encrypting. When I try to decrypt, however, it always brings up the prompt for the passphrase despite having set it via a c.set_passphrase_cb callback. Am I doing something wrong?

A: 

does anyone know how this can be solved? I have the same problem. Thanks!!

+1  A: 

Hi, I have a similar problem. My code looks like this:

def passphrase_callback(hint='', desc='', prev_bad=''): return 'password'

class CryptoEngine: class NoSignKeys(Exception): def init(self, str): Exception.init(self, str)

def __init__(self, user_id, passphrase):
    "Initialize with ID (e-mail)"
    self.user_id = user_id
    self.passphrase = passphrase
def verify(self, data):
    c = core.Context()
    sig = core.Data(string = data)
    file = None
    plain = core.Data()
    c.op_verify(sig, file, plain)
    result = c.op_verify_result()
    plain.seek(0, 0)
    plaintext = plain.read()
    sig = result.signatures
    status = False
    for s in sig:
        status = (s.status == 0)
    return status, plaintext

def sign(self, data):
    c = core.Context()
    for sigkey in c.op_keylist_all(self.user_id, 1):
        if sigkey.can_sign:
            c.signers_add(sigkey)
    if not c.signers_enum(0):
        raise CryptoEngine.NoSignKeys("No secret %s's keys suitable for signing" % self.user_id)

    plain = core.Data(data)
    sig = core.Data()
    c.set_passphrase_cb(passphrase_callback)
    c.op_sign(plain, sig, mode.CLEAR)
    sig.seek(0, 0)
    return sig.read()

Despite setting the passphrase callback I still either get a message box asking for the passphrase or just an exception notifying of a bad password. Did someone solve this problem and could share his knowledge? Thanks, Yan

Yan
A: 

Add "c.set_armor(1)" before you set the passphrase callback.

anonymous coward