From b6c57ed294f86861303206a6bded745dac763f34 Mon Sep 17 00:00:00 2001 From: RubenCGomes Date: Tue, 19 Nov 2024 22:30:31 +0000 Subject: [PATCH] removed password param --- delivery1/lib/symmetric_encryption.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/delivery1/lib/symmetric_encryption.py b/delivery1/lib/symmetric_encryption.py index d2a2520..ada1660 100644 --- a/delivery1/lib/symmetric_encryption.py +++ b/delivery1/lib/symmetric_encryption.py @@ -5,7 +5,7 @@ from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.backends import default_backend # Function to derive a 256-bit key from a password and salt -def derive_key(passwd, salt): +def derive_key(salt): kdf = PBKDF2HMAC( algorithm=hashes.SHA256(), length=32, @@ -13,14 +13,12 @@ def derive_key(passwd, salt): iterations=10000, backend=default_backend() ) - key = kdf.derive(passwd.encode()) - return key.hex() + return kdf.derive(b'') -# Function to encrypt a file using a password -def encrypt_file(passwd, input_file, output_file): - salt = os.urandom(16) - key = derive_key(passwd, salt) +# Function to encrypt a file using a salt +def encrypt_file(salt, input_file, output_file): + key = derive_key(salt) iv = os.urandom(16) cipher = Cipher(algorithms.AES(key), modes.CFB(iv), backend=default_backend()) encryptor = cipher.encryptor() @@ -34,15 +32,15 @@ def encrypt_file(passwd, input_file, output_file): f.write(salt + iv + ciphertext) -# Function to decrypt a file using a password -def decrypt_file(passwd, input_file, output_file=None): +# Function to decrypt a file +def decrypt_file(input_file, output_file=None): with open(input_file, 'rb') as f: encrypted_data = f.read() salt = encrypted_data[:16] iv = encrypted_data[16:32] ciphertext = encrypted_data[32:] - key = derive_key(passwd, salt) + key = derive_key(salt) cipher = Cipher(algorithms.AES(key), modes.CFB(iv), backend=default_backend()) decryptor = cipher.decryptor()