python和编程新手。目前正在编写一个小python3代码来保存我的银行帐户登录详细信息等。我已经通过打开和关闭一个文件,并使用out='filename'for gnupg模块,但理想情况下,我希望它写入内存,因为我不希望磁盘上的解密信息,如果我可以避免它。在
该文件是由程序中的另一个函数创建的,该函数将词典进行pickle并将其加密到一个文件中。但是当我试图解密并打开它时:
def OpenDictionary():
""" open the dictionary file """
if os.path.isfile(SAVEFILE):
f = open(SAVEFILE, 'rb')
print('opening gpg file')
buf = io.BytesIO()
decrypted_data = gpg.decrypt_file(f, passphrase=PASSWORD)
buf.write(decrypted_data.data)
print ('ok: ', decrypted_data.ok)
print ('status: ', decrypted_data.status)
print ('stderr: ', decrypted_data.stderr)
f.close()
dictionary = pickle.load(buf)
buf.close()
return dictionary
我得到:
^{pr2}$同样的结果在我的Linux机器上。我已经试了很多方法来完成这个任务,但到目前为止还没有成功。有谁能提出更好的方法吗?基本上我需要gpg.decrypt_文件输出到缓冲区或变量,以及酸洗。装载把它读回字典。在
感谢@senderle
相关问题 更多 >
编程相关推荐