How to sign a file and then verify?
Question: 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!


Answer: Use [`python-gpgme`](https://launchpad.net/pygpgme) (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.

