[git] GPGME - branch, master, updated. gpgme-1.11.1-117-ged5ef82

by Ben McGinnes cvs at cvs.gnupg.org
Mon Aug 13 18:23:54 CEST 2018


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG Made Easy".

The branch, master has been updated
       via  ed5ef8293cdbfcc3b91268eeae1eb6b4f8d271bb (commit)
      from  94bf13e78e65e1d1bc2e5d6b2311f9c9657bfe5f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit ed5ef8293cdbfcc3b91268eeae1eb6b4f8d271bb
Author: Ben McGinnes <ben at adversary.org>
Date:   Tue Aug 14 02:22:36 2018 +1000

    Symmetric encryption example.
    
    * lang/python/examples/howto/symcrypt-file.py: A variation on standard
      key based encryption.

diff --git a/lang/python/examples/howto/symcrypt-file.py b/lang/python/examples/howto/symcrypt-file.py
new file mode 100755
index 0000000..2b24284
--- /dev/null
+++ b/lang/python/examples/howto/symcrypt-file.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+import gpg
+import sys
+
+# Copyright (C) 2018 Ben McGinnes <ben at gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+"""
+Symmetrically encrypts a file.  Passphrase will be prompted for via Pinentry.
+
+Will produce both an ASCII armoured and GPG binary format copy of the encrypted
+file.
+"""
+
+if len(sys.argv) > 2:
+    filename = " ".join(sys.argv[1:])
+elif len(sys.argv) == 2:
+    filename = sys.argv[1]
+else:
+    filename = input("Enter the path and filename to encrypt: ")
+
+with open(filename, "rb") as f:
+    text = f.read()
+
+with gpg.Context(armor=True) as ca:
+    try:
+        ciphertext, result, sign_result = ca.encrypt(text, passphrase=None,
+                                                     sign=False)
+        with open("{0}.asc".format(filename), "wb") as fa:
+            fa.write(ciphertext)
+    except gpg.errors.InvalidRecipients as e:
+        print(e)
+
+with gpg.Context() as cg:
+    try:
+        ciphertext, result, sign_result = cg.encrypt(text, passphrase=None,
+                                                     sign=False)
+        with open("{0}.gpg".format(filename), "wb") as fg:
+            fg.write(ciphertext)
+    except gpg.errors.InvalidRecipients as e:
+        print(e)

-----------------------------------------------------------------------

Summary of changes:
 .../howto/{encrypt-file.py => symcrypt-file.py}      | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)
 copy lang/python/examples/howto/{encrypt-file.py => symcrypt-file.py} (74%)


hooks/post-receive
-- 
GnuPG Made Easy
http://git.gnupg.org




More information about the Gnupg-commits mailing list