from cryptography.fernet import Fernet from pathlib import Path class CryptoManager: """ Класс для симметричного шифрования и расшифрования файлов. """ def generate_key(self) -> bytes: return Fernet.generate_key() def encrypt_file(self, file_path: str, key: bytes, output_path: str) -> None: fernet = Fernet(key) data = Path(file_path).read_bytes() encrypted = fernet.encrypt(data) Path(output_path).write_bytes(encrypted) def decrypt_file(self, file_path: str, key: bytes, output_path: str) -> None: fernet = Fernet(key) data = Path(file_path).read_bytes() decrypted = fernet.decrypt(data) Path(output_path).write_bytes(decrypted)