'Simplest yet secure way of using gpg in python?

I want to encrypt some plaintext in python using a key that's been generated through the gpg2 commandline. The application will only know the public key, and would encrypt the data before storage into a database.

I know there is python-gnupg, but that's only been tested on gpg 1.4.2. The latest stable is gpg 2.0.19, which adds some new bugfixes and features. There's pycrypto, but that seems bulky to use for a simple encryption step.

I could use the subprocess module and just use gpg2, but I am unsure about the security implications of running external programs from python.

Is there a pure python wrapper for gpg that I can use? Or would using the subprocess module to call gpg2 be sufficient?



Solution 1:[1]

You can try python-pgp.

Here are some other alternatives:

  • pyassuan - communicate with GnuPG using its socket protocol.
  • gnupg - a wrapper around the GnuPG executable.
  • python-gnupg - another wrapper around the GnuPG executable.
  • another wrapper around the GnuPG executable.
  • gpglib - a pure python library for parsing OpenPGP packets and decrypting messages.
  • OpenPGP - an unmaintained pure python library with much of the functionality of old versions of GnuPG.
  • encryptedfile - a pure python library for symmetrically encrypting files in an OpenPGP-compatible way.
  • PGPy - a pure python library with basic parsing and signing of OpenPGP packets.
  • OpenPGP-Python - a pure python port of openpgp-php. It can parse OpenPGP packets and verify & create signatures.

But, in my case, none of these will work. If I can find what I am looking for, I will be sure to update this post with a lot more information.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hg0428