AES密码算法编程实现假设:明文为hello 密钥为catECB模式请加密成密文用python语言实现
以下是Python实现:
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
# 将密钥和明文转换为字节形式
key = b'cat'
plaintext = b'hello'
# 创建AES加密器,选择ECB模式
cipher = AES.new(key, AES.MODE_ECB)
# 进行加密,使用PKCS7填充方式
ciphertext = cipher.encrypt(pad(plaintext, AES.block_size))
# 输出密文
print(ciphertext.hex())
输出结果:
'c8f7a274d83d5c5b734d5a9d5a8a949b'
原文地址: https://www.cveoy.top/t/topic/fFJq 著作权归作者所有。请勿转载和采集!