Skip to content

Instantly share code, notes, and snippets.

@sfstpala
Created May 26, 2013 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfstpala/5654253 to your computer and use it in GitHub Desktop.
Save sfstpala/5654253 to your computer and use it in GitHub Desktop.
GPG Signatue with python3-gpgme
#!/usr/bin/python3
import io
import gpgme
def sign(filename):
context = gpgme.Context()
context.armor = True
context.signers = tuple(i for i in context.keylist() if i.can_sign)
signature = io.BytesIO()
with open(filename, "rb") as f:
context.sign(f, signature, gpgme.SIG_MODE_DETACH)
return signature.getvalue().decode('ascii')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment