2021-11-21 04:23:03 +00:00
|
|
|
from cryptography.fernet import Fernet
|
|
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
secret_key = settings.CHAT_SECRET_KEY
|
|
|
|
fernet = Fernet(secret_key)
|
|
|
|
|
2022-05-14 17:57:27 +00:00
|
|
|
|
2021-11-21 04:23:03 +00:00
|
|
|
def encrypt_url(creator_id, other_id):
|
2022-05-14 17:57:27 +00:00
|
|
|
message = str(creator_id) + "_" + str(other_id)
|
2021-11-21 04:23:03 +00:00
|
|
|
return fernet.encrypt(message.encode()).decode()
|
|
|
|
|
2022-05-14 17:57:27 +00:00
|
|
|
|
2021-11-21 04:23:03 +00:00
|
|
|
def decrypt_url(message_encrypted):
|
|
|
|
try:
|
|
|
|
dec_message = fernet.decrypt(message_encrypted.encode()).decode()
|
2022-05-14 17:57:27 +00:00
|
|
|
creator_id, other_id = dec_message.split("_")
|
2021-11-21 04:23:03 +00:00
|
|
|
return int(creator_id), int(other_id)
|
|
|
|
except Exception as e:
|
2022-05-14 17:57:27 +00:00
|
|
|
return None, None
|