fix crypto import

This commit is contained in:
wh1te909 2020-06-30 08:03:36 +00:00
parent 7c610c1134
commit 22b65ca06d
1 changed files with 8 additions and 5 deletions

View File

@ -1,15 +1,18 @@
import time
from base64 import b64encode
from Cryptodome.Cipher import AES
from Cryptodome.Random import get_random_bytes
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
def get_auth_token(user, key):
key = bytes.fromhex(key)
key1 = key[0:32]
msg = '{{"userid":"{}", "domainid":"{}", "time":{}}}'.format(f"user//{user}", "", int(time.time()))
msg = '{{"userid":"{}", "domainid":"{}", "time":{}}}'.format(
f"user//{user}", "", int(time.time())
)
iv = get_random_bytes(12)
a = AES.new(key1, AES.MODE_GCM, iv)
msg, tag = a.encrypt_and_digest(bytes(msg, 'utf-8'))
msg, tag = a.encrypt_and_digest(bytes(msg, "utf-8"))
return b64encode(iv + tag + msg, altchars=b"@$").decode("utf-8")
return b64encode(iv + tag + msg, altchars=b"@$").decode("utf-8")