doc: python bindings howto
* Added description for detached signatures.
This commit is contained in:
parent
ada059b071
commit
e5c85fba25
@ -823,19 +823,43 @@
|
||||
:CUSTOM_ID: howto-basic-signing-clear
|
||||
:END:
|
||||
|
||||
Though PGP/in-line messages are no longer encouraged in favour of
|
||||
PGP/MIME, there is still sometimes value in utilising in-line
|
||||
signatures. This is where clearsigned messages or text is of
|
||||
value.
|
||||
|
||||
#+begin_src python
|
||||
import gpg
|
||||
|
||||
text = """Declaration of ... something.
|
||||
text0 = """Declaration of ... something.
|
||||
|
||||
"""
|
||||
text = text0.encode("utf-8")
|
||||
|
||||
c = gpg.Context()
|
||||
signed = c.sign(text, mode=2)
|
||||
|
||||
afile = open("/path/to/statement.txt.asc", "w")
|
||||
for i in range(len(signed[0].splitlines())):
|
||||
afile.write("{0}\n".format(signed[0].splitlines()[i].decode('utf-8')))
|
||||
for line in signed[0].splitlines():
|
||||
afile.write("{0}\n".format(line.decode("utf-8")))
|
||||
afile.close()
|
||||
#+end_src
|
||||
|
||||
In spite of the appearance of a clearsigned message, the data
|
||||
handled by GPGME in signing it must still be byte literals.
|
||||
|
||||
#+begin_src python
|
||||
import gpg
|
||||
|
||||
tfile = open("/path/to/statement.txt", "rb")
|
||||
text = tfile.read()
|
||||
tfile.close()
|
||||
|
||||
c = gpg.Context()
|
||||
signed = c.sign(text, mode=2)
|
||||
|
||||
afile = open("/path/to/statement.txt.asc", "wb")
|
||||
afile.write(signed[0])
|
||||
afile.close()
|
||||
#+end_src
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user