diff options
| author | Ben McGinnes <[email protected]> | 2018-03-18 21:49:17 +0000 | 
|---|---|---|
| committer | Ben McGinnes <[email protected]> | 2018-03-18 21:49:17 +0000 | 
| commit | 4811ff7b6c8ef97c7d4858ce235e9bf8227f4917 (patch) | |
| tree | 64eee1b2a2c77fe3536b5acde18715cfae6903e7 /lang/python/docs | |
| parent | doc: python bindings howto (diff) | |
| download | gpgme-4811ff7b6c8ef97c7d4858ce235e9bf8227f4917.tar.gz gpgme-4811ff7b6c8ef97c7d4858ce235e9bf8227f4917.zip | |
doc: python bindings howto
* moved single encrytion examples up to the first ones, pending merge
  and major cut.
* This is basically just to make future checks of revisions a little easier.
Diffstat (limited to 'lang/python/docs')
| -rw-r--r-- | lang/python/docs/GPGMEpythonHOWTOen.org | 128 | 
1 files changed, 64 insertions, 64 deletions
| diff --git a/lang/python/docs/GPGMEpythonHOWTOen.org b/lang/python/docs/GPGMEpythonHOWTOen.org index a2144235..c0606dd9 100644 --- a/lang/python/docs/GPGMEpythonHOWTOen.org +++ b/lang/python/docs/GPGMEpythonHOWTOen.org @@ -511,6 +511,70 @@  	     print(ex.getstring())     #+end_src +*** Encrypting to one key using the second method +    :PROPERTIES: +    :CUSTOM_ID: howto-basic-encryption-monogamous +    :END: + +    This example re-creates the first encryption example except it +    uses the same =encrypt= method used in the subsequent examples +    instead of the =op_encrypt= method.  This means that, unlike the +    =op_encrypt= method, it /must/ use byte literal input data. + +    #+begin_src python +      import gpg + +      rkey = "0x12345678DEADBEEF" +      text = b"""Some text to test with. + +      Since the text in this case must be bytes, it is most likely that +      the input form will be a separate file which is opened with "rb" +      as this is the simplest method of obtaining the correct data +      format. +      """ + +      c = gpg.Context(armor=True) +      rpattern = list(c.keylist(pattern=rkey, secret=False)) +      logrus = [] + +      for i in range(len(rpattern)): +	  if rpattern[i].can_encrypt == 1: +	      logrus.append(rpattern[i]) + +      cipher = c.encrypt(text, recipients=logrus, sign=False, always_trust=True) + +      with open("secret_plans.txt.asc", "wb") as afile: +          afile.write(cipher[0]) +    #+end_src + +    With one or two exceptions, this method will probably prove to be +    easier to implement than the first method and thus it is the +    recommended encryption method.  Though it is even more likely to +    be used like this: + +    #+begin_src python +      import gpg + +      rkey = "0x12345678DEADBEEF" + +      afile = open("secret_plans.txt", "rb") +      text = afile.read() +      afile.close() + +      c = gpg.Context(armor=True) +      rpattern = list(c.keylist(pattern=rkey, secret=False)) +      logrus = [] + +      for i in range(len(rpattern)): +	  if rpattern[i].can_encrypt == 1: +	      logrus.append(rpattern[i]) + +      cipher = c.encrypt(text, recipients=logrus, sign=False, always_trust=True) + +      with open("secret_plans.txt.asc", "wb") as afile: +          afile.write(cipher[0]) +    #+end_src +  *** Encrypting to multiple keys      :PROPERTIES:      :CUSTOM_ID: howto-basic-encryption-multiple @@ -610,70 +674,6 @@      This will attempt to encrypt to all the keys searched for, then      remove invalid recipients if it fails and try again. -*** Encrypting to one key using the second method -    :PROPERTIES: -    :CUSTOM_ID: howto-basic-encryption-monogamous -    :END: - -    This example re-creates the first encryption example except it -    uses the same =encrypt= method used in the subsequent examples -    instead of the =op_encrypt= method.  This means that, unlike the -    =op_encrypt= method, it /must/ use byte literal input data. - -    #+begin_src python -      import gpg - -      rkey = "0x12345678DEADBEEF" -      text = b"""Some text to test with. - -      Since the text in this case must be bytes, it is most likely that -      the input form will be a separate file which is opened with "rb" -      as this is the simplest method of obtaining the correct data -      format. -      """ - -      c = gpg.Context(armor=True) -      rpattern = list(c.keylist(pattern=rkey, secret=False)) -      logrus = [] - -      for i in range(len(rpattern)): -	  if rpattern[i].can_encrypt == 1: -	      logrus.append(rpattern[i]) - -      cipher = c.encrypt(text, recipients=logrus, sign=False, always_trust=True) - -      with open("secret_plans.txt.asc", "wb") as afile: -          afile.write(cipher[0]) -    #+end_src - -    With one or two exceptions, this method will probably prove to be -    easier to implement than the first method and thus it is the -    recommended encryption method.  Though it is even more likely to -    be used like this: - -    #+begin_src python -      import gpg - -      rkey = "0x12345678DEADBEEF" - -      afile = open("secret_plans.txt", "rb") -      text = afile.read() -      afile.close() - -      c = gpg.Context(armor=True) -      rpattern = list(c.keylist(pattern=rkey, secret=False)) -      logrus = [] - -      for i in range(len(rpattern)): -	  if rpattern[i].can_encrypt == 1: -	      logrus.append(rpattern[i]) - -      cipher = c.encrypt(text, recipients=logrus, sign=False, always_trust=True) - -      with open("secret_plans.txt.asc", "wb") as afile: -          afile.write(cipher[0]) -    #+end_src -  ** Decryption     :PROPERTIES: | 
