Quiz registration form
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
from os import path
|
||||
from os import environ, path
|
||||
from cryptography.fernet import Fernet
|
||||
|
||||
def generate_keyfile():
|
||||
@ -14,14 +14,25 @@ def load_key():
|
||||
def check_keyfile_exists():
|
||||
return path.isfile('./security/.encryption.key')
|
||||
|
||||
def encrypt(input:str):
|
||||
input = input.encode()
|
||||
def encrypt(input):
|
||||
if not check_keyfile_exists():
|
||||
generate_keyfile()
|
||||
_encryption_key = load_key()
|
||||
fernet = Fernet(_encryption_key)
|
||||
output = fernet.encrypt(input)
|
||||
return output.decode()
|
||||
if type(input) == str:
|
||||
input = input.encode()
|
||||
output = fernet.encrypt(input)
|
||||
return output.decode()
|
||||
if type(input) == dict:
|
||||
output = {}
|
||||
for key,value in input.items():
|
||||
if type(value) == dict:
|
||||
output[key] = encrypt(value)
|
||||
else:
|
||||
value = value.encode()
|
||||
output[key] = fernet.encrypt(value)
|
||||
output[key] = output[key].decode()
|
||||
return output
|
||||
|
||||
def decrypt(input):
|
||||
if not check_keyfile_exists():
|
||||
|
Reference in New Issue
Block a user