如何用pyme签名数据?
我刚在我的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
但我不知道该如何创建这样的对象。
1 个回答
0
你可以参考pyme文档中的例子,然后稍微修改一下:
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()