python aes加解密 ecb模式 加密 报错ValueError: Data must be aligned to block boundary in ECB mode

from Crypto.Util.Padding import pad, unpad
from Crypto.Cipher import AES
BLOCK_SIZE = 32 # Bytes

key = 'abcdefghijklmnop'
cipher = AES.new(key.encode('utf8'), AES.MODE_ECB)
msg = cipher.encrypt(pad(b'hello', BLOCK_SIZE))
print(msg.hex())
decipher = AES.new(key.encode('utf8'), AES.MODE_ECB)
msg_dec = decipher.decrypt(msg)
print(unpad(msg_dec, BLOCK_SIZE))
需要用block_size 补充位数

此处是模拟php openssl_encrypt($data, "AES-128-ECB", $key, OPENSSL_RAW_DATA)

 

你可能感兴趣的:(#,加解密应用)