I'm trying to make an encrypted password manager. I've got almost everything done, except for saving the password along with the username and the site where I use it. When I execute the function that writes it to a file I get:
TypeError: a bytes-like object is required, not 'str'
The code is this and I'm using cryptography to encrypt the passwords:
from cryptography.fernet import Fernet
import errors
def write(text, key):
"""Encrypt and writes something to the passlist.encrypted file
Arguments:
text -- The list that will be written in the passlist.encrypted file
key -- The main key, generated from password"""
try:
if type(text) == list:
file = open('passlist.encrypted', 'wb')
for i in text:
message = i.encode()
f = Fernet(key)
encrypted = f.encrypt(message)
print(encrypted, file = file)
if i == text[-1]:
file.close()
else:
raise errors.invalidValueTypeError
except errors.invalidValueTypeError:
print('Error: Text must be a list')
Also, I'm trying to make that every string in the text
list uses a different line and the previous text is not overwritten, but I can't make it work.