Python Pyme:无需用户交互的简单解密

发布于 2024-08-02 06:42:34 字数 122 浏览 3 评论 0原文

我正在使用 Pyme 与 GPGME 交互,并且签名/加密没有任何问题。然而,当我尝试解密时,尽管已通过 c.set_passphrase_cb 回调设置了密码,但它始终会提示输入密码。难道我做错了什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

↙温凉少女 2024-08-09 06:42:34

我有一个类似的问题。
我的代码如下所示:

def passphrase_callback(hint='', desc='', prev_bad=''):
返回“密码”

类 CryptoEngine:
类 NoSignKeys(异常):
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()

尽管设置了密码回调,我仍然收到一个消息框,询问
密码或只是通知错误密码的异常。
有人解决了这个问题并可以分享他的知识吗?
谢谢,

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

旧梦荧光笔 2024-08-09 06:42:34

在设置密码回调之前添加“c.set_armor(1)”。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文