我正在尝试使用模块就地加密文件cryptography
,因此我不必缓冲文件的密文,这可能会占用大量内存,然后我将不得不用加密的文件替换原始文件。所以我的解决方案是加密一个块明文,然后尝试将其替换为一次 16 个字节的密文(AES-CTR 模式)。问题似乎是循环是无限循环。
那么如何解决这个问题。
你建议什么其他方法。
使用下面这种方法有什么副作用。
pointer = 0
with open(path, "r+b") as file:
print("...ENCRYPTING")
while file:
file_data = file.read(16)
pointer += 16
ciphertext = aes_enc.update(file_data)
file.seek(pointer-16)
file.write(ciphertext)
print("...Complete...")
慕村9548890
繁星点点滴滴
相关分类