import binascii from Crypto.Cipher import AES #秘钥,此处需要将字符串转为字节 from utils import config from utils.env_operation import conf_parse key = b'abcdefgh' #加密内容需要长达16位字符,所以进行空格拼接 class crypt_util(): def __init__(self): self.token = config.get_env('crypt_token').encode('utf-8') self.aes = AES.new(self.token, AES.MODE_CBC,b'0000000000000000') def encrypt(self,text): text = text.encode('utf-8') # 这里密钥key 长度必须为16(AES-128), # 24(AES-192),或者32 (AES-256)Bytes 长度 # 目前AES-128 足够目前使用 length = 16 count = len(text) if count < length: add = (length - count) # backspace # text = text + (' ' * add) text = text + ('