public static void EncryptFile(string fileName, string key, CipherType cipherType, int n) { try { string plainText = File.ReadAllText(fileName); string cipherText = ParallelCipher.Encrypt(plainText, key, cipherType, n); File.WriteAllText(fileName, cipherText); MessageBox.Show("The file has been encrypted"); } catch (UnauthorizedAccessException) { MessageBox.Show("Access error"); } catch (DirectoryNotFoundException) { MessageBox.Show("Didectory not found"); } catch (FileNotFoundException) { MessageBox.Show("File not found"); } catch (Exception e) { MessageBox.Show("Unexpected error: " + e.Message); } }
private void button2_Click(object sender, EventArgs e) { if ((textBox3.Text == "") && (label4.Text == "Файл не выбран") || firstUsing) { MessageBox.Show("Введите текст для шифрования"); return; } if (!int.TryParse(textBox1.Text, out n)) { MessageBox.Show("Некорректное число рабочих"); return; } if (n <= 0) { MessageBox.Show("Число рабочих должно быть больше нуля"); return; } CipherType c; if (cipherType == "DES") { c = CipherType.DES; } else { c = CipherType.AES; } if (fileName != "") { FileCryptor.EncryptFile(fileName, key, c, n); fileName = ""; label4.Text = "Файл не выбран"; } else { textBox4.Text = ParallelCipher.Encrypt(plainText, key, c, n); } }