Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sign a file and then verify? [closed]

I am writing an application in which I sync a file to a server where I want to sign the file then send it back to the client where it can be verified.

There seem to be multiple gnupg modules for Python for Ubuntu/Debian:

python-gnupginterface - Python interface to GnuPG (GPG)

python-gpgme - python wrapper for the GPGME library

python-gpgme-dbg - python wrapper for the GPGME library (debug extension)

python-pyme - Python interface to the GPGME GnuPG encryption library

python-pyme-doc - Python interface to the GPGME GnuPG encryption library

Can someone recommend which I one I should use that gets me up and running quickly?

Should I just shell out to gpg instead of using a Python module?

Thanks!

like image 791
Jono Bacon Avatar asked Oct 24 '22 09:10

Jono Bacon


2 Answers

Use python-gpgme (as a bonus, you probably know the maintainer).

Here's how you can use it to sign something (check with jamesh if there's a better way, I haven't use this extensively):

import gpgme
from io import BytesIO

ctx = gpgme.Context()
plain = BytesIO("Hello")
sign = BytesIO("")

ctx.sign(plain, sign, gpgme.SIG_MODE_CLEAR)
print sign.getvalue()

in case it's not clear, BytesIO is a file-like thing. You could give it file("/etc/passwd") as plain and sys.stdout as sign and it'd DWYW.

like image 118
Chipaca Avatar answered Oct 26 '22 02:10

Chipaca


You can use http://code.google.com/p/python-gnupg/

It wraps command line GnuPG. I use it to encrypt/sign and decrypt/verify files.

like image 30
Michał Niklas Avatar answered Oct 26 '22 01:10

Michał Niklas