【发布时间】:2020-04-29 22:46:16
【问题描述】:
在运行测试以确保两个不同的库提供相同的输出时,我发现CFB 并没有。复制问题的代码是:
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from Crypto.Cipher import AES
KEY = b'legoroojlegorooj'
IV = b'legoroojlegorooj'
aes = Cipher(algorithms.AES(KEY), modes.CFB(IV), default_backend()).encryptor()
output_data = aes.update(b'Feathers fall as fast as bowling balls.') + aes.finalize()
del aes
ctr = AES.new(KEY, AES.MODE_CFB, iv=IV)
output_data2 = ctr.encrypt(b'Feathers fall as fast as bowling balls.')
assert output_data == output_data2 # AssertionError
如有任何帮助解决这个问题,我们将不胜感激。
此代码适用于 modes.OFB(IV) 和 AES.MODE_OFB。
【问题讨论】:
-
你是什么意思“不要使用某些模式” - 你能发布你得到的错误(见How to Ask)
-
@ErtySeidohl 抱歉,这是我最初的草稿 - 没必要,我会删除它。
标签: python encryption aes pycryptodome python-cryptography