我正试图使一个密码锁,需要输入和加密的数据,也正试图保存到字典的数据和加密的价值观只。
from cryptography.fernet import Fernet
key = Fernet.generate_key()
f = Fernet(key)
loc = {} # an empty dict that stores the keys and values
title = input('enter your title: ') # getting user title as key
secret = input('enter your secret: ') # getting secret as value to be encrypted
loc[title] = secret.encode() #turning the value into a byte for encryption
print(f.encrypt(secret)) # but am having an error trying to get through
字符串
任何帮助将不胜感激。谢谢。
1条答案
按热度按时间ttygqcqt1#
有一段时间了,但是...
我会加密整个dict,但在此之前,你需要将dict转换为字节:
字符串
在另一端,你会解密它并将字节转换回dict:
型