aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/docs/GPGMEpythonHOWTOen.org
diff options
context:
space:
mode:
authorBen McGinnes <[email protected]>2018-03-12 20:42:04 +0000
committerBen McGinnes <[email protected]>2018-03-12 20:42:04 +0000
commit484e9a6229ac9c80c6be4df638bce711f08a74c6 (patch)
treeb5c47b07884cec04850f17c279eacfba07291bba /lang/python/docs/GPGMEpythonHOWTOen.org
parentdoc: python bindings howto (diff)
downloadgpgme-484e9a6229ac9c80c6be4df638bce711f08a74c6.tar.gz
gpgme-484e9a6229ac9c80c6be4df638bce711f08a74c6.zip
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).
Diffstat (limited to 'lang/python/docs/GPGMEpythonHOWTOen.org')
-rw-r--r--lang/python/docs/GPGMEpythonHOWTOen.org20
1 files changed, 19 insertions, 1 deletions
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