From 484e9a6229ac9c80c6be4df638bce711f08a74c6 Mon Sep 17 00:00:00 2001 From: Ben McGinnes Date: Tue, 13 Mar 2018 07:42:04 +1100 Subject: [PATCH] doc: python bindings howto * updated multi-encryption final example to be complete. * second example shows most likely method of reading plaintext. * updated example filenames to stick with running gag (i.e. secret_plans.txt). --- lang/python/docs/GPGMEpythonHOWTOen.org | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lang/python/docs/GPGMEpythonHOWTOen.org b/lang/python/docs/GPGMEpythonHOWTOen.org index 46bd231b..622475f4 100644 --- a/lang/python/docs/GPGMEpythonHOWTOen.org +++ b/lang/python/docs/GPGMEpythonHOWTOen.org @@ -384,7 +384,7 @@ cipher = c.encrypt(text, recipients=rlogrus, sign=False, always_trust=True) - afile = open("encrypted_file.txt.asc", "wb") + afile = open("secret_plans.txt.asc", "wb") afile.write(cipher[0]) afile.close() #+end_src @@ -409,6 +409,20 @@ somewhat with something more like this: #+begin_src python + import gpg + + afile = open("secret_plans.txt", "rb") + text = afile.read() + afile.close() + + c = gpg.Context(armor=True) + rpattern = list(c.keylist(pattern="@gnupg.org", secret=False)) + rlogrus = [] + + for i in range(len(rpattern)): + if rpattern[i].can_encrypt == 1: + rlogrus.append(rpattern[i]) + try: cipher = c.encrypt(text, recipients=rlogrus, add_encrypt_to=True) except gpg.errors.InvalidRecipients as e: @@ -422,6 +436,10 @@ cipher = c.encrypt(text, recipients=rlogrus, add_encrypt_to=True) except: pass + + afile = open("secret_plans.txt.asc", "wb") + afile.write(cipher[0]) + afile.close() #+end_src This will attempt to encrypt to all the keys searched for, then