Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do symmetric encryption with the python gnupg module vers. 1.2.5?

I'm trying to do symmetric encryption with python and gnupg.

This code snippet works on my windows vista machine, on which the python gnupg module is version 0.3.2:

import gnupg
gpg = gnupg.GPG()
data = 'the quick brown fow jumps over the laxy dog.'
passphrase='12345'
crypt = gpg.encrypt(data, recipients=None,
                     symmetric='AES256',
                     passphrase=passphrase,
                     armor=False)

When I try to run it on my linux machine with the version 1.2.5 python gnupg module I get this error:

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "/usr/local/lib/python2.7/dist-packages/gnupg/gnupg.py", line 961, in encrypt
    result = self._encrypt(stream, recipients, **kwargs)
TypeError: _encrypt() got multiple values for keyword argument 'recipients'

I have done a number of searches and can't find anything on this.

like image 350
user3601780 Avatar asked May 04 '14 17:05

user3601780


People also ask

Does GPG use symmetric encryption?

Overview. GnuPG is a hybrid-encryption software program because it uses a combination of conventional symmetric-key cryptography for speed, and public-key cryptography for ease of secure key exchange, typically by using the recipient's public key to encrypt a session key which is used only once.


1 Answers

This is an old ask, but I came upon this in a Google search and was unhappy with the provided answers. I found the real answer in python-gnupg's GitHub issues:

gpg.encrypt(data, symmetric='AES256', passphrase=passphrase, armor=False, encrypt=False)

So, drop the recipients=None and add an encrypt=False. Your crypt.data will then contain the encrypted data. Unintuitive, but it works.

(src: https://github.com/isislovecruft/python-gnupg/issues/110)

like image 133
Victoria Avatar answered Oct 02 '22 18:10

Victoria