public void HandleEncryption(EncryptionParams encryptionParams) { var dataToProcess = ReadAllBytesFromFile(encryptionParams.InputFileName); var key = ReadAllBytesFromFile(encryptionParams.KeyFileName); _symmetricCipherManager.Key = key; _symmetricCipherManager.CipherMode = encryptionParams.SymmetricCipherMode; _symmetricCipherManager.CipherBlockSize = encryptionParams.CipherBlockSize; if (encryptionParams.SymmetricCipherMode is not SymmetricCipherMode.ElectronicCodeBook) { var initializationVector = ReadAllBytesFromFile(encryptionParams.InitializationVectorFileName); _symmetricCipherManager.InitializationVector = initializationVector; } var processedData = new byte[] {}; switch (encryptionParams.CipherAction) { case CipherAction.Encrypt: processedData = _symmetricCipherManager.Encrypt(dataToProcess); break; case CipherAction.Decrypt: processedData = _symmetricCipherManager.Decrypt(dataToProcess); break; } WriteAllBytesToFile(encryptionParams.OutputFileName, processedData); }
private void Decrypt() { Console.WriteLine("Введите имя файла для расшифровки"); var inputFileName = Console.ReadLine(); Console.WriteLine("Введите имя файла, который нужно сохранить"); var outputFileName = Console.ReadLine(); Console.WriteLine("Введите имя файла ключа, который нужно сохранить"); var keyFileName = Console.ReadLine(); var encryptionParams = new EncryptionParams(CipherAction.Decrypt, _cipherBlockSize, SymmetricCipherMode.ElectronicCodeBook, inputFileName, outputFileName, keyFileName); _symmetricSystem.HandleEncryption(encryptionParams); }