如何使用python gnupg模块vers进行对称加密. 1.2.5?
作者:互联网
我正在尝试使用python和gnupg进行对称加密.
这段代码片段适用于我的windows vista机器,python gnupg模块的版本为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)
当我尝试使用版本1.2.5 python gnupg模块在我的linux机器上运行它时,我收到此错误:
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'
我做了很多搜索,但在这方面找不到任何东西.
解决方法:
这是一个古老的问题,但我在谷歌搜索中发现了这一点,并对提供的答案不满意.我在python-gnupg的GitHub问题中找到了真正的答案:
gpg.encrypt(data,symmetric =’AES256′,passphrase = passphrase,armor = False,encrypt = False)
因此,删除recipients = None并添加encrypt = False.然后,您的crypt.data将包含加密数据.不直观,但它的确有效.
(src:https://github.com/isislovecruft/python-gnupg/issues/110)
标签:python,encryption,gnupg 来源: https://codeday.me/bug/20190624/1278957.html