Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 957
user1812844 Avatar asked Nov 30 '25 14:11

user1812844


1 Answers

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.

like image 164
Hg0428 Avatar answered Dec 03 '25 11:12

Hg0428



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!