I am trying to encrypt a password, store that password in a text file and then later I would retrieve that encrypted password and decrypt it in python. I've gotten the encryption working, and storing it in the text file however when trying to decrypt it again it says:
AttributeError: 'str' object has no attribute 'decode'. I copy and pasted the encrypted message which was in bytes I think into the text file, so Im not sure how else to decrypt it.
salt = b'salt123'
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=32,
salt=salt,
iterations=100000,
backend=default_backend()
)
test_password = 'test123'.encode()
key = base64.urlsafe_b64encode(kdf.derive(test_password))
f = Fernet(key)
encrypted = f.encrypt(test_password) #This is the encrypted password which I copy and pasted into the text file
password = []
f = open("Passwords.txt", "r")
if f.mode == 'r':
for line in f:
password.append(line)
f.close()
#password[2] is the encrypted password
decrypted_pass = f.decrypt(password[2]) #Error AttributeError: 'str' object has no attribute 'decode'
EDIT: made a mistake, meant to decrypt in the last line not decode