removed password param

This commit is contained in:
RubenCGomes 2024-11-19 22:30:31 +00:00
parent 9cbb6ba721
commit b6c57ed294
1 changed files with 8 additions and 10 deletions

View File

@ -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()