python-AES加密

import base64
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad

BLOCK_SIZE = 16

def aes_encrypt(text, key, IV):
    """
    AES加密
    :param text:
    :return:
    """
    text = bytes(str(text), 'utf-8')
    cipher = AES.new(key, AES.MODE_CBC, IV)
    # 加密
    ciphertext = cipher.encrypt(pad(text, BLOCK_SIZE))
    # 返回 base64 编码的密文字符串
    b64_ciphertext = base64.b64encode(ciphertext).decode()
    print(f"加密后参数= {b64_ciphertext}")
    return b64_ciphertext

你可能感兴趣的:(python)