Changed functions for encryption and decryption of accounts to use str of master_pass instead of bytes

This commit is contained in:
2022-11-09 19:02:58 +03:00
parent f7f954ecd3
commit c2280e8bc2
3 changed files with 7 additions and 8 deletions

View File

@ -20,12 +20,12 @@ def _generate_key(salt: bytes, master_pass: bytes) -> bytes:
def encrypt_account_info(
login: str, passwd: str, master_pass: bytes
login: str, passwd: str, master_pass: str
) -> tuple[bytes, bytes, bytes]:
"""Encrypts login and password of a user using their master password as a key.
Returns a tuple of encrypted login, password and salt"""
salt = os.urandom(64)
key = _generate_key(salt, master_pass)
key = _generate_key(salt, master_pass.encode("utf-8"))
f = Fernet(key)
enc_login = f.encrypt(login.encode("utf-8"))
enc_passwd = f.encrypt(passwd.encode("utf-8"))
@ -33,11 +33,11 @@ def encrypt_account_info(
def decrypt_account_info(
enc_login: bytes, enc_pass: bytes, master_pass: bytes, salt: bytes
enc_login: bytes, enc_pass: bytes, master_pass: str, salt: bytes
) -> tuple[str, str]:
"""Decrypts login and password using their master password as a key.
Returns a tuple of decrypted login and password"""
key = _generate_key(salt, master_pass)
key = _generate_key(salt, master_pass.encode("utf-8"))
f = Fernet(key)
login_bytes = f.decrypt(enc_login)
pass_bytes = f.decrypt(enc_pass)