python 在 Windows下使用AES时要安装的是pycryptodome 模块
python 在 Linux下使用AES时要安装的是pycrypto模块
from Cryptodome.Cipher import AES
import base64
class AEScoder():
def __init__(self):
self.__encryptKey = "dre4567890gt"
# AES加密
def encrypt(self, content):
sec_key = AES.new(self.__encryptKey.encode('utf-8'), AES.MODE_ECB)
encrData = sec_key.encrypt(self.pad_to_16(content))
return encrData
# AES解密
def decrypt(self, content):
base64_decrypt = base64.decodebytes(content)
return sec_key.decrypt(base64_decrypt).strip(b"\x00")
def pad_to_16(self, value):
while len(value) % 16 != 0:
value += b"\x00"
return value
if __name__ == '__main__':
data_json = {"username": "admin", "password": "aaaa", "uuid": "cc271abe"}
url = "https://192.168.1.66:1550/login"
headers = {"Content-Type": "application/json;charset=UTF-8"}
headers["token"] = "e9f50ee4"
params = AEScoder().encrypt(json.dumps(data_json).encode("utf-8"))
content = base64.encodebytes(params)
response = requests.post(url, headers=headers, data=content, verify=False)
print(response.json())