我正在尝试使用 pyme(来自 gpgme 的 python 包装器)解密消息。如果我在提示时输入密码,它工作正常,但我无法让密码回调工作。这是代码
import pyme.core
def Callback( x, y, z ):
print 'in passphrase callback'
return 'passphrase'
plain = pyme.core.Data()
cipher = pyme.core.Data(sys.stdin.read())
c = pyme.core.Context()
c.set_armor(1)
c.set_passphrase_cb(Callback)
c.op_decrypt( cipher, plain )
plain.seek(0,0)
print plain.read()
当我运行它并且不以交互方式提供密码时,程序会尝试“在密码回调中”进行回调打印,但随后失败并出现错误:
pyme.errors.GPGMEError: Invocation of gpgme_op_decrypt: Unspecified source: General error (0,1)
首先,为什么密码回调不起作用?其次,如何防止程序在调用密码回调之前提示用户输入密码?
这是在 Ubuntu 10.04 上运行的