(
input_file: io.BytesIO, output_file: io.BytesIO, iv: bytes, key: bytes
)
| 7 | |
| 8 | |
| 9 | def decrypt_file( |
| 10 | input_file: io.BytesIO, output_file: io.BytesIO, iv: bytes, key: bytes |
| 11 | ): |
| 12 | cipher = Cipher(algorithms.AES256(key), modes.CBC(iv)) |
| 13 | decryptor = cipher.decryptor() |
| 14 | padder = padding.PKCS7(128).unpadder() |
| 15 | while True: |
| 16 | chunk = input_file.read(4096) |
| 17 | if not chunk: |
| 18 | break |
| 19 | decrypted = decryptor.update(chunk) |
| 20 | unpadded_chunk = padder.update(decrypted) |
| 21 | output_file.write(unpadded_chunk) |
| 22 | output_file.write(padder.update(decryptor.finalize())) |
| 23 | output_file.write(padder.finalize()) |
| 24 | output_file.flush() |
| 25 | output_file.seek(0) |
no outgoing calls