init
This commit is contained in:
25
utils/crypto.py
Normal file
25
utils/crypto.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import os
|
||||
import hashlib
|
||||
import base64
|
||||
from datetime import datetime
|
||||
|
||||
class Crypto:
|
||||
@staticmethod
|
||||
def create_session_key(account_uid: str) -> str:
|
||||
random_bytes = os.urandom(64)
|
||||
temp = f"{account_uid}.{datetime.now().timestamp()}.{random_bytes.hex()}"
|
||||
try:
|
||||
hash_bytes = hashlib.sha512(temp.encode('utf-8')).digest()
|
||||
return base64.b64encode(hash_bytes).decode('utf-8')
|
||||
except Exception as e:
|
||||
hash_bytes = hashlib.sha512(temp.encode('utf-8')).digest()
|
||||
return base64.b64encode(hash_bytes).decode('utf-8')
|
||||
|
||||
|
||||
def generate_dispatch_token(uid) -> str:
|
||||
dispatch_token = Crypto.create_session_key(uid)
|
||||
return dispatch_token
|
||||
|
||||
def generate_combo_token(uid) -> str:
|
||||
dispatch_token = Crypto.create_session_key(uid)
|
||||
return dispatch_token
|
||||
Reference in New Issue
Block a user