【发布时间】:2021-09-23 22:47:35
【问题描述】:
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
key = b'InformationSecurity M.Sc'
message = b"""yeahcourse snake"""
IV = '000102030405060708090a0b0c0d0e0f'
aesCipher = Cipher(algorithms.AES(key),
modes.CBC(),
backend=default_backend())
aesEncryptor = aesCipher.encryptor()
aesDecryptor = aesCipher.decryptor()
message += b"E" * (-len(message) % 16) # Padding to full blocks of 16 bytes
ciphertext = aesEncryptor.update(message)
print("plaintext:",message)
print("ciphertext:",ciphertext.hex())
decryptedMessage = aesDecryptor.update(ciphertext)
print("recovered:",decryptedMessage)
一直是 ECB 模式,但现在想将其更改为 CBC 模式。当 aes 运行代码时,它会显示以下消息:
TypeError: __init__() missing 1 required positional argument: 'initialization_vector'
【问题讨论】:
-
提问时请贴出整个回溯。