我对python很陌生,我的代码很基础,但是我仍然添加注释来帮助任何人理解这只花了20分钟,但这是一个模块,因此我可以在代码中输入密码。但是我真的在解码功能方面苦苦挣扎,任何解决方案都很棒。
想要的结果是它将解码文本文档中的代码,当我从.txt文件中读取代码时,我检查了它的字节数,因为我使用了“ rb”,但它一直显示: >
ValueError:Fernet密钥必须为32个url安全的base64编码字节。
def DecryptPassword():
#import modules
from cryptography.fernet import Fernet
#send the display message
print("")
print("Decoding")
#read key for file
Rlocation = "C:\\Users\\marcu\\OneDrive\\Desktop\\Crypto Python\\Password Moduale\\HashKey.txt"
#Open file
oprb = open(Rlocation,"rb")
#read file .txt
Rkey = oprb.readline()
#close file
oprb.close()
#change key to bytes
print(type(Rkey))
###########################################
#decode
f2 = Fernet(Rkey)
#set decode var
decrypted_pass = f2.decode()
return decrypted_pass