Mon Jun 26 15:25:26 CEST 2023
This commit is contained in:
+15
-6
@@ -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 ""
|
||||
|
||||
Reference in New Issue
Block a user