aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/docs/GPGMEpythonHOWTOen.org
diff options
context:
space:
mode:
authorBen McGinnes <[email protected]>2018-03-08 18:25:49 +0000
committerBen McGinnes <[email protected]>2018-03-08 18:25:49 +0000
commitc767a4a3590bd8a224d0268746df443942cb28c2 (patch)
treed01ca3874fbb1638ec0689af1aa2e13d0acf61f5 /lang/python/docs/GPGMEpythonHOWTOen.org
parentdoc: Basic operation of the python bindings (diff)
downloadgpgme-c767a4a3590bd8a224d0268746df443942cb28c2.tar.gz
gpgme-c767a4a3590bd8a224d0268746df443942cb28c2.zip
doc: python bindings howto update
* Added example of decryption. * included some quick notes for myself regarding aspects to explain when I flesh out the explanatory text.
Diffstat (limited to 'lang/python/docs/GPGMEpythonHOWTOen.org')
-rw-r--r--lang/python/docs/GPGMEpythonHOWTOen.org38
1 files changed, 36 insertions, 2 deletions
diff --git a/lang/python/docs/GPGMEpythonHOWTOen.org b/lang/python/docs/GPGMEpythonHOWTOen.org
index 8f81511c..ab7e9db8 100644
--- a/lang/python/docs/GPGMEpythonHOWTOen.org
+++ b/lang/python/docs/GPGMEpythonHOWTOen.org
@@ -269,7 +269,6 @@ Python bindings to programmatically leverage the GPGME library.
#+begin_src python
import gpg
import os
- import os.path
rkey = "0x12345678DEADBEEF"
text = """
@@ -297,13 +296,48 @@ Python bindings to programmatically leverage the GPGME library.
cipher.seek(0, os.SEEK_SET)
del(text)
del(plain)
- afile = open("secret_plans.txt.asc", "wb")
+ afile = open("secret_plans.org.asc", "wb")
afile.write(cipher.read())
afile.close()
except gpg.errors.GPGMEError as ex:
print(ex.getstring())
#+end_src
+** Decryption
+ :PROPERTIES:
+ :CUSTOM_ID: howto-basic-encryption
+ :END:
+
+ Decrypting something encrypted to a key in one's secret keyring
+ (will display some extra data you normally wouldn't show, but which
+ may be of use):
+
+ #+begin_src python
+ import os.path
+ import gpg
+
+ if os.path.exists("/path/to/secret_plans.org.asc") is True:
+ ciphertext = "/path/to/secret_plans.org.asc"
+ elif os.path.exists("/path/to/secret_plans.org.gpg") is True:
+ ciphertext = "/path/to/secret_plans.org.gpg"
+ else:
+ ciphertext = None
+
+ if ciphertext is not None:
+ afile = open(ciphertext, "rb")
+ plaintext = gpg.Context().decrypt(afile)
+ afile.close()
+ newfile = open("/path/to/secret_plans.org", "wb")
+ newfile.write(plaintext[0])
+ newfile.close()
+ print(plaintext[0])
+ plaintext[1]
+ plaintext[2]
+ del(plaintext)
+ else:
+ pass
+ #+end_src
+
* Copyright and Licensing
:PROPERTIES: