【问题标题】:how do I sign data with pyme?如何使用 pyme 签署数据?
【发布时间】:2009-10-07 10:34:35
【问题描述】:

我刚刚在我的 ubuntu 系统上安装了 pyme。这很容易(感谢 apt-get),我可以重现示例代码(使用我的密钥环中的公钥加密)。现在我想签署一些数据,但我没有找到任何示例代码,也没有找到太多文档。

这就是我一直在做的:

>>> plain = pyme.core.Data('this is just some sample text\n')
>>> cipher = pyme.core.Data()
>>> c = pyme.core.Context()
>>> c.set_armor(1)
>>> name='me@office.com'
>>> c.op_keylist_start(name, 0)
>>> r = c.op_keylist_next()
>>> c.op_sign(???)

我不知道该给什么作为参数,op_sign 方法告诉我

>>> help(c.op_sign)
Help on function _funcwrap in module pyme.util:

_funcwrap(*args, **kwargs)
    gpgme_op_sign(ctx, plain, sig, mode) -> gpgme_error_t

但我不知道如何创建这样的对象。

【问题讨论】:

    标签: python encryption gnupg gpgme pyme


    【解决方案1】:

    您可以按照 pyme doc 中的示例进行一些修改:

    import pyme.core
    import pyme.pygpgme
    
    plaintext = pyme.core.Data('this is a test message')
    ciphertext = pyme.core.Data()
    ctx = pyme.core.Context()
    ctx.set_armor(1)
    name = 'me@office.com'
    ctx.op_keylist_start(name, 0)
    key = ctx.op_keylist_next()
    # first argument is message to sign, second argument is buffer where to write
    # the signature, third argument is signing mode, see
    # http://www.gnupg.org/documentation/manuals/gpgme/Creating-a-Signature.html#Creating-a-Signature for more details.
    ctx.op_sign(plaintext, ciphertext, pyme.pygpgme.GPGME_SIG_MODE_CLEAR)
    ciphertext.seek(0, 0)
    print ciphertext.read()
    

    【讨论】:

    • 嗨,谢谢...但是您在 pyme 文档中哪里找到的?
    • @mariotomo,pyme 文档中有一个简单的快速启动程序。只需导入 pyme 和 help(pyme)。
    • 导入pyme;帮助(pyme):但是'''显然'''这是我做的第一件事:)。在我的两个系统(Debian 不稳定和 ubuntu 9.04)上,我得到的文本中没有 op_sign。你用的是其他的吗?
    • @mariotomo,我刚刚尝试了 SourceForge 的 pyme-0.8.1.tar.gz;导入pyme;交互式 python 提示中的 help(pyme) 显示了文档。我不知道 Debian 软件包出了什么问题(如果有的话)。
    猜你喜欢
    • 1970-01-01
    • 2011-01-02
    • 2021-11-02
    • 2022-07-25
    • 2014-02-22
    • 2018-08-27
    • 2012-11-29
    • 2020-05-17
    相关资源
    最近更新 更多