Pergunta

Acabei de instalar pyme no meu sistema Ubuntu. Foi fácil (obrigado apt-get) e eu posso reproduzir o código de exemplo (criptografar usando uma chave pública no meu chaveiro). Agora eu gostaria de sinal Alguns dados e eu não conseguimos encontrar nenhum código de exemplo nem muita documentação.

É isso que tenho feito:

>>> 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(???)

Não sei o que dar como parâmetros, o op_sign O método me diz

>>> 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

Mas não sei como criar esses objetos.

Foi útil?

Solução

Você pode seguir o exemplo do Pyme Doc e modificá -lo um pouco:

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()
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top