makes decrypt return text or write into file

This commit is contained in:
RubenCGomes 2024-11-19 20:29:00 +00:00
parent e537f9087a
commit 25b8edae4a
1 changed files with 6 additions and 3 deletions

View File

@ -107,14 +107,17 @@ def decrypt_hybrid(private_key, encrypted_data):
# main function to decrypt the file # main function to decrypt the file
def decrypt_file(private_key, encrypted_file, decrypted_file): def decrypt_file(private_key, encrypted_file, decrypted_file=None):
with open(encrypted_file, 'rb') as f: with open(encrypted_file, 'rb') as f:
encrypted_content = f.read() encrypted_content = f.read()
decrypted_content = decrypt_hybrid(private_key, encrypted_content) decrypted_content = decrypt_hybrid(private_key, encrypted_content)
with open(decrypted_file, 'wb') as f: if decrypted_file is None:
f.write(decrypted_content) return decrypted_content
else:
with open(decrypted_file, 'wb') as f:
f.write(decrypted_content)
# function to load a private key from a file # function to load a private key from a file