如何用pyme签署数据?

2024-06-02 04:31:29 发布

您现在位置:Python中文网/ 问答频道 /正文

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

这就是我一直在做的:

>>> 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方法告诉我

^{pr2}$

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


Tags: 代码namecore示例datagetubuntu系统
1条回答
网友
1楼 · 发布于 2024-06-02 04:31:29

您可以按照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()

相关问题 更多 >