Compare commits
2 Commits
63de9010de
...
b4c6e17ce2
Author | SHA1 | Date | |
---|---|---|---|
b4c6e17ce2 | |||
2ea3096fb0 |
@ -27,8 +27,8 @@ def encrypt_account_info(
|
|||||||
salt = os.urandom(64)
|
salt = os.urandom(64)
|
||||||
key = _generate_key(salt, master_pass.encode("utf-8"))
|
key = _generate_key(salt, master_pass.encode("utf-8"))
|
||||||
f = Fernet(key)
|
f = Fernet(key)
|
||||||
enc_login = f.encrypt(login.encode("utf-8"))
|
enc_login = base64.urlsafe_b64decode(f.encrypt(login.encode("utf-8")))
|
||||||
enc_passwd = f.encrypt(passwd.encode("utf-8"))
|
enc_passwd = base64.urlsafe_b64decode(f.encrypt(passwd.encode("utf-8")))
|
||||||
return (enc_login, enc_passwd, salt)
|
return (enc_login, enc_passwd, salt)
|
||||||
|
|
||||||
|
|
||||||
@ -39,6 +39,6 @@ def decrypt_account_info(
|
|||||||
Returns a tuple of decrypted login and password"""
|
Returns a tuple of decrypted login and password"""
|
||||||
key = _generate_key(salt, master_pass.encode("utf-8"))
|
key = _generate_key(salt, master_pass.encode("utf-8"))
|
||||||
f = Fernet(key)
|
f = Fernet(key)
|
||||||
login_bytes = f.decrypt(enc_login)
|
login_bytes = f.decrypt(base64.urlsafe_b64encode(enc_login)).decode("utf-8")
|
||||||
pass_bytes = f.decrypt(enc_pass)
|
pass_bytes = f.decrypt(base64.urlsafe_b64encode(enc_pass)).decode("utf-8")
|
||||||
return (login_bytes.decode("utf-8"), pass_bytes.decode("utf-8"))
|
return (login_bytes, pass_bytes)
|
||||||
|
@ -25,8 +25,8 @@ class Account(sqlmodel.SQLModel, table=True):
|
|||||||
sa_column=sqlmodel.Column(sqlmodel.BINARY(64), nullable=False)
|
sa_column=sqlmodel.Column(sqlmodel.BINARY(64), nullable=False)
|
||||||
)
|
)
|
||||||
enc_login: bytes = sqlmodel.Field(
|
enc_login: bytes = sqlmodel.Field(
|
||||||
sa_column=sqlmodel.Column(sqlmodel.VARBINARY(500), nullable=False)
|
sa_column=sqlmodel.Column(sqlmodel.VARBINARY(256), nullable=False)
|
||||||
)
|
)
|
||||||
enc_pass: bytes = sqlmodel.Field(
|
enc_pass: bytes = sqlmodel.Field(
|
||||||
sa_column=sqlmodel.Column(sqlmodel.VARBINARY(500), nullable=False)
|
sa_column=sqlmodel.Column(sqlmodel.VARBINARY(256), nullable=False)
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user