I'm trying to implement symmetric encryption using python's wrapper to gpgme, pygpgme. Unfortunately I'm using gpg 2.0.22 and gpg-agent 2.0.22. This mailing list post says that the passphrase callback is ignored in 2.0, which is the issue I'm running in to.
When I run the following code, I always get an error saying 'Bad passphrase', but I'm not even prompted for one. Ideally though I'd like to be able to supply the passphrase on behalf of the user:
import gpgme
def passphrase_cb(uid_hint, passphrase_info, prev_was_bad, fd):
print "Entered passphrase_cb"
print "uid_hint=%s passphrase_info=%s" % (uid_hint, passphrase_info)
def main():
ctx = gpgme.Context()
ctx.armor = False
ctx.passphrase_cb = passphrase_cb
ctx.set_engine_info(gpgme.PROTOCOL_OpenPGP, "/usr/local/bin/gpg",
"/Users/me/Library/Application Support/temp/test")
input_path = "/tmp/input.pdf"
enc_output_path = "/tmp/output.pdf.gpg"
with open(input_path, 'rb') as input:
with open(enc_output_path, 'wb') as enc_output:
res = ctx.encrypt(None,
gpgme.ENCRYPT_ALWAYS_TRUST,
input,
enc_output)
passphrase_cb
is never called.
How can I supply a passphrase so I can perform symmetric encryption?
Well it's not so important. I'll just shell out to the gpg binary for symmetric crypto. I found this answer useful.