问题描述
我正在尝试使用pyme(来自gpgme的python包装器)解密消息.如果我在提示时输入密码,则可以正常工作,但是我无法使密码短语回调起作用.这是代码
I am trying to decrypt messages using pyme (a python wrapper from gpgme). It works fine if I type in the password when it prompts but I cannot get the passphrase callback to work. Here is the code
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()
当我运行此命令并且不以交互方式提供密码时,程序将尝试使用在密码短语回调中"进行回调打印,但会失败并显示错误:
When I run this and don't provide the password interactively the program then tries the Callback printing 'in passphrase callback' but then fails with error:
pyme.errors.GPGMEError: Invocation of gpgme_op_decrypt: Unspecified source: General error (0,1)
首先,为什么密码短语回调不起作用?其次,如何防止程序在调用密码短语回调之前提示用户输入密码?
First and foremost, why does the passphrase callback not work? And secondly, how can I prevent the program from prompting the user for a password before calling the passphrase callback?
它在Ubuntu 10.04上运行
This is running on Ubuntu 10.04
推荐答案
显然,您需要解释关键字hook
:
apparently, you need to interpret the keyword hook
:
def Callback( x, y, z, hook=None):
...
效果很好.
这篇关于在没有用户交互的情况下使用pyme解密python中的PGP问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!