ENCRYPTION_KEY, docs

This commit is contained in:
jokob-sk
2024-12-31 10:14:01 +11:00
parent 8ac4112ab9
commit e52601e062
31 changed files with 183 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
import base64
import os
import hashlib
@@ -41,4 +42,18 @@ def decrypt_data(data, encryption_key):
ct = base64.b64decode(data[24:])
cipher = AES.new(key, AES.MODE_CBC, iv)
pt = unpad(cipher.decrypt(ct), AES.block_size)
return pt.decode('utf-8')
return pt.decode('utf-8')
#-------------------------------------------------------------------------------
def get_random_bytes(length):
# Generate random bytes
random_bytes = os.urandom(length)
# Convert bytes to hexadecimal string
hex_string = random_bytes.hex()
# Format hexadecimal string with hyphens
formatted_hex = '-'.join(hex_string[i:i+2] for i in range(0, len(hex_string), 2))
return formatted_hex