Initial Commit

This commit is contained in:
Neill Cox 2024-08-10 14:13:07 +10:00
commit 05c2e5e81f
17 changed files with 1197 additions and 0 deletions

22
ah_tools/helpers.py Normal file
View file

@ -0,0 +1,22 @@
import base64
import sys
from cryptography.fernet import Fernet
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
def decrypt(salt, password, data):
kdf = PBKDF2HMAC(algorithm=hashes.SHA256(), length=32, salt=salt.encode("ascii"), iterations=480000)
key = base64.urlsafe_b64encode(kdf.derive(password.encode('ascii')))
f = Fernet(key)
return f.decrypt(data.encode("ascii")).decode("ascii")
def encrypt(salt, password, data):
kdf = PBKDF2HMAC(algorithm=hashes.SHA256(), length=32, salt=salt.encode("ascii"), iterations=480000)
key = base64.urlsafe_b64encode(kdf.derive(password.encode('ascii')))
f = Fernet(key)
return f.encrypt(data.encode("ascii")).decode("ascii")