怎么才能让AES 解密后的内容变 bytes 类型 并且是 单斜杠
from Cryptodome.Cipher import AES
import base64
BLOCK_SIZE = 16 # Bytes
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * \
chr(BLOCK_SIZE - len(s) % BLOCK_SIZE)
unpad = lambda s: s[:-ord(s[len(s) - 1:])]
def aesDecrypt(key, data):
'''
:param key: 密钥
:param data: 加密后的数据(密文)
:return:明文
'''
key = key.encode('utf8')
data = base64.b64decode(data)
cipher = AES.new(key, AES.MODE_ECB)
# 去补位
text_decrypted = unpad(cipher.decrypt(data))
text_decrypted = text_decrypted.decode('utf8')
return text_decrypted
if __name__ == '__main__':
data = "ZTGKHEpEDu4SErowHwkeANiyFmUZgNvlrodx3RZPr1c="
key = "5c44c819appsapi0"
exp = aesDecrypt(key,data)
print("正常解密str类型:",type(exp))
print(exp)
print('------------------------------')
expByts = str.encode(exp)
print("变bytes类型:",type(expByts))
print(expByts)
结果
正常解密str类型: <class 'str'>
\x4d\x5a\x41\x52\x55\x48\x89
------------------------------
变bytes类型: <class 'bytes'>
b'\\x4d\\x5a\\x41\\x52\\x55\\x48\\x89'