diff --git a/delivery2/lib/symmetric_encryption.py b/delivery2/lib/symmetric_encryption.py index 040a697..be4d385 100644 --- a/delivery2/lib/symmetric_encryption.py +++ b/delivery2/lib/symmetric_encryption.py @@ -35,6 +35,8 @@ def encrypt_file(input_file, output_file=None): # Function to decrypt a file def decrypt_file(key, input_file, output_file=None): + plaintext_content = b"" + with open(input_file, 'rb') as infile: # Read the IV from the input file iv = infile.read(16) @@ -46,9 +48,19 @@ def decrypt_file(key, input_file, output_file=None): while chunk := infile.read(2048): plaintext = decryptor.update(chunk) outfile.write(plaintext) + plaintext_content += plaintext # Finalize decryption - outfile.write(decryptor.finalize()) + final_chunk = decryptor.finalize() + outfile.write(final_chunk) + plaintext_content += final_chunk + else: + while chunk := infile.read(2048): + plaintext = decryptor.update(chunk) + plaintext_content += plaintext - return True + # Finalize decryption + plaintext_content += decryptor.finalize() + + return plaintext_content