【发布时间】:2020-09-22 05:38:43
【问题描述】:
下午好,我正在尝试编写一个程序来读取 .bmp 文件并使用给定的初始值加密它,使用 ????????????和一次性便笺簿。
前 36 个字节构成图像的头部,没有加密,只是复制到新文件中
从 0x36 开始到末尾的图像数据被分组为四个字节的字,每个字使用 ???????????? 加密。
为避免更改图像大小,请勿包含 ????0=????????????在加密的图像中。
到目前为止,这就是我所拥有的:
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
from Crypto.Util import Counter
filename = "Image11.bmp"
filename_out = "Image11Encrypted.bmp"
key = 0xe0984dd3
bkey = key.to_bytes(32, 'big')
cipher = AES.new(bkey, AES.MODE_CTR, initial_value= 0xff128eff)
def encrypt(filename, filename_out, key):
with open(filename, "rb") as f:
clear = f.read()
clear_trimmed = clear[64:-2]
ciphertext = clear_trimmed
ciphertext = cipher.encrypt(pad(clear_trimmed, 16))
ciphertext = clear[0:64] + ciphertext + clear[-2:]
with open(filename_out, "wb") as f:
f.write(ciphertext)
encrypt(filename, filename_out, key)
print("Encrypted using AES in CTR mode and saved to \"" + filename_out + "\"")
但是,我一直遇到这个错误:
.
任何帮助都会很棒,不知道从哪里开始
【问题讨论】:
-
代码和错误应该作为文本发布在这里,而不是图片
-
文档建议
counter应该是Crypto.Util.Counter类型,而不是数字(值为0xff128eff)。
标签: python encryption aes