1234567891011121314151617181920212223242526272829303132 |
- import base64
- import hashlib
- from Crypto.Cipher import AES
- def md5(text):
- text = text.encode(encoding='utf-8')
- m = hashlib.md5()
- m.update(text)
- return m.hexdigest()
- def aes_encrypt(key, data):
- try:
- mode = AES.MODE_ECB
- padding = lambda s: s + (16 - len(s) % 16) * chr(16 - len(s) % 16)
- cryptos = AES.new(key, mode)
- cipher_text = cryptos.encrypt(padding(data).encode("utf-8"))
- return base64.b64encode(cipher_text).decode("utf-8")
- except Exception as e:
- return ""
- def aes_decrypt(key, data):
- try:
- cryptos = AES.new(key, AES.MODE_ECB)
- decrpytBytes = base64.b64decode(data)
- meg = cryptos.decrypt(decrpytBytes).decode('utf-8')
- return meg[:-ord(meg[-1])]
- except Exception as e:
- return ""
|