from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
import base64
KEY = '' # 密钥
IV = b'' # 偏移量
BLOCK_SIZE = 16
def aes_decrypt(ciphertext, key):
"""
AES解密
:param ciphertext:
:param key:
:return:
"""
b_key = key.encode()
cipher = AES.new(b_key, AES.MODE_CBC, IV)
# 先base64编码一手
base64Str = base64.b64decode(ciphertext)
# 再解码一手
dec_text = cipher.decrypt(base64Str).decode()
# 去除补位
dec_text = dec_text[:-ord(dec_text[-1])]
return str(dec_text)
python-AES-CBC解密
于 2023-10-08 13:57:01 首次发布