Mon Jun 26 15:25:26 CEST 2023

This commit is contained in:
mnjx
2023-06-26 16:33:38 +02:00
parent 8168ff3cd4
commit 8b1a6643b5
7 changed files with 297 additions and 249 deletions
+15 -6
View File
@@ -49,9 +49,13 @@ def encrypt_and_write_to_file(password: str, strdata: str, file_path: str) -> bo
f = Fernet(key)
encrypted = f.encrypt(strdata.encode())
with open(file_path, "wb") as ef:
ef.write(encrypted)
if os.path.exists(file_path):
with open(file_path, "wb") as ef:
ef.write(encrypted)
else:
os.system(f"touch {file_path}")
with open(file_path, "wb") as ef:
ef.write(encrypted)
return 0
except:
@@ -68,9 +72,14 @@ def read_from_file_and_decrypt(password: str, file_path: str) -> str:
f = Fernet(key)
with open(file_path, "rb") as ef:
decrypted = f.decrypt(ef.read())
if os.path.exists(file_path):
with open(file_path, "rb") as ef:
decrypted = f.decrypt(ef.read())
else:
os.system(f"touch {file_path}")
with open(file_path, "rb") as ef:
decrypted = f.decrypt(ef.read())
return decrypted.decode()
except:
return ""