0

我刚刚安装pyme在我的ubuntu系统上。这很容易(感谢 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

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

4

1 回答 1

0

您可以按照 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()
于 2009-10-07T11:56:06.870 回答