4AES密码算法编程实现使用pycryptodome库假设:明文为hello 密钥为catECB模式请加密成密文用python语言实现
from Crypto.Cipher import AES
将明文和密钥都转换为字节串
plaintext = b'hello' key = b'cat'
创建AES加密器对象
cipher = AES.new(key, AES.MODE_ECB)
对明文进行填充
plaintext_padded = plaintext + (AES.block_size - len(plaintext) % AES.block_size) * b'\0'
加密明文
ciphertext = cipher.encrypt(plaintext_padded)
打印密文
print(ciphertext.hex())
原文地址: https://www.cveoy.top/t/topic/gdlw 著作权归作者所有。请勿转载和采集!