如何使用python gnupg加密数据而不设置收件人
我正在使用python gnupg在本地对称加密文件(因此不会发送给任何人)。如何使用python gnupg加密数据而不设置收件人,python,encryption,gnupg,Python,Encryption,Gnupg,我正在使用python gnupg在本地对称加密文件(因此不会发送给任何人)。 问题是:当收件人设置为None时,会出现以下错误 Traceback (most recent call last): File "/home/michelojordan/Documents/project_file/gpg_cryptography.py", line 32, in <module> file_encryption("lkdzmmza6532ad
问题是:当收件人设置为
None
时,会出现以下错误
Traceback (most recent call last):
File "/home/michelojordan/Documents/project_file/gpg_cryptography.py", line 32, in <module>
file_encryption("lkdzmmza6532adz")
File "/home/michelojordan/Documents/project_file/gpg_cryptography.py", line 8, in file_encryption
enc_data = gpg.encrypt(data, recipients=None, symmetric=True, passphrase=encryption_key)
File "/home/michelojordan/.local/lib/python3.9/site-packages/gnupg/gnupg.py", line 1064, in encrypt
result = self._encrypt(stream, recipients, **kwargs)
TypeError: _encrypt() got multiple values for argument 'recipients'
Python gnupg版本是0.4.7Python版本是3.9.2
系统:kali linux 5.10.0
我已经被困了3周了,所以非常感谢您的帮助。奇怪的是,我没有在Python gnupg 0.4.7中找到回溯中的代码。进一步查看,我发现了一些具有类似名称的不同库。你有可能把他们弄糊涂了吗?
import gnupg, os
def file_encryption(encryption_key):
gpg = gnupg.GPG()
with open("data_file.csv", "rb") as data_file:
data = data_file.read()
enc_data = gpg.encrypt(data, recipients=None, symmetric=True, passphrase=encryption_key)
with open("enc_file.txt", "wb") as enc_file:
enc_file.write(enc_data.data)
os.remove("data_file.csv")
def file_decryption(decryption_key):
gpg = gnupg.GPG()
with open("enc_file.txt", "rb") as enc_file:
read_data = enc_file.read()
dec_data = gpg.decrypt(read_data, passphrase=decryption_key)
with open("data_file.csv", 'a+') as dec_file:
dec_file.write(dec_data.data.decode())
with open("data_file.csv", "a+") as file:
file.write('message to encrypt')
file_encryption("passcode")