2022-06-19 13:22:05 +01:00
|
|
|
from flask import current_app as app
|
|
|
|
|
2022-06-11 13:26:50 +01:00
|
|
|
from cryptography.fernet import Fernet
|
2022-06-19 13:22:05 +01:00
|
|
|
from pathlib import Path
|
2022-06-11 13:26:50 +01:00
|
|
|
|
|
|
|
def load_key():
|
2022-06-19 13:22:05 +01:00
|
|
|
data = Path(app.config.get('DATA'))
|
2022-06-11 13:26:50 +01:00
|
|
|
with open(f'./{data}/.encryption.key', 'rb') as keyfile: return keyfile.read()
|
|
|
|
|
|
|
|
def decrypt(input:str):
|
|
|
|
encryption_key = load_key()
|
|
|
|
fernet = Fernet(encryption_key)
|
|
|
|
input = input.encode()
|
|
|
|
output = fernet.decrypt(input)
|
|
|
|
return output.decode()
|
|
|
|
|
|
|
|
def encrypt(input:str):
|
|
|
|
encryption_key = load_key()
|
|
|
|
fernet = Fernet(encryption_key)
|
|
|
|
input = input.encode()
|
|
|
|
output = fernet.encrypt(input)
|
|
|
|
return output.decode()
|