encrypt.py 803 B

12345678910111213141516171819202122232425262728
  1. import base64
  2. import json
  3. import time
  4. import uuid
  5. from Crypto.Cipher import AES
  6. def encrypt_padding(string: str, block_size: int) -> str:
  7. length = len(string.encode('utf-8'))
  8. add_length = block_size - (length % block_size)
  9. return string + (chr(add_length) * add_length)
  10. def aes_encrypt(string: str, aes_key: str) -> str:
  11. cipher = AES.new(aes_key.encode('utf-8'), AES.MODE_ECB)
  12. cipher_text = cipher.encrypt(encrypt_padding(string, AES.block_size).encode('utf-8'))
  13. cipher_text = base64.b64encode(cipher_text)
  14. return cipher_text.decode()
  15. def genRat(url: str,emp:int) -> str:
  16. mi = {
  17. 't': int(time.time() * 1000),
  18. 'w': str(uuid.uuid4()),
  19. 'r': url,
  20. 'u': emp
  21. }
  22. return aes_encrypt(json.dumps(mi), '253140fdc9c44b0cb903c387b3e85d64')