private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         Console.WriteLine("Инициализация дешифровчика...");
         RCC5 decrypter = new RCC5(Encoding.ASCII.GetBytes(textBox1.Text));
         Console.WriteLine("Готово. Открытие файла...");
         FileStream openfile = File.OpenRead(path);
         byte[]     dfile    = new byte[openfile.Length];
         openfile.Read(dfile, 0, dfile.Length);
         openfile.Close();
         Console.WriteLine("Готово. Дешифровка файла...");
         dfile = decrypter.Decode(dfile);
         Console.WriteLine("Готово.");
         string text = Encoding.ASCII.GetString(dfile);
         if (checkBox1.Checked)
         {
             Clipboard.SetText(text);
         }
         MessageBox.Show((checkBox2.Checked ? "Password: "******"\n" : "") + (checkBox1.Checked ? "Password been copied to the clipboard." : ""), "Decrypted", MessageBoxButtons.OK, MessageBoxIcon.Information);
         this.Close();
     }
     catch (Exception ex)
     {
         if (ex.Message.Equals("Ключ неверный или файл повреждён."))
         {
             try
             {
                 Console.WriteLine("Инициализация старого дешифровчика...");
                 RCC4 decrypter = new RCC4(Encoding.ASCII.GetBytes(textBox1.Text));
                 Console.WriteLine("Готово. Открытие файла...");
                 FileStream openfile = File.OpenRead(path);
                 byte[]     dfile    = new byte[openfile.Length];
                 openfile.Read(dfile, 0, dfile.Length);
                 openfile.Close();
                 Console.WriteLine("Готово. Дешифровка файла...");
                 dfile = decrypter.Decode(dfile);
                 Console.WriteLine("Готово.");
                 string text = Encoding.ASCII.GetString(dfile);
                 if (checkBox1.Checked)
                 {
                     Clipboard.SetText(text);
                 }
                 MessageBox.Show((checkBox2.Checked ? "Password: "******"\n" : "") + (checkBox1.Checked ? "Password been copied to the clipboard." : ""), "Decrypted", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 MessageBox.Show("Алгоритм шифрования этого файла устарел и в скором времени его поддержка будет остановлена! \nВо избежании потери пароля, пожалуйста перешифруйте его в этой программе!", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 this.Close();
             }catch (Exception exc)
             {
                 MessageBox.Show(exc.Message, exc.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         else
         {
             MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Example #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (isMatch && isSave)
     {
         try
         {
             Console.WriteLine("Инициализация шифровчика...");
             RCC5 crypter = new RCC5(Encoding.ASCII.GetBytes(textBox1.Text));
             Console.WriteLine("Готово. Шифрование файла...");
             byte[] efile = crypter.Encode(file);
             Console.WriteLine("Готово. Сохранение...");
             FileStream savefile = File.Create(path);
             savefile.Write(efile, 0, efile.Length);
             savefile.Close();
             MessageBox.Show("Файл сохранён", "Инфо", MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.Close();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else if (!isSave)
     {
         try
         {
             RCC4       decrypter = new RCC4(Encoding.ASCII.GetBytes(textBox1.Text));
             FileStream openfile  = File.OpenRead(path);
             byte[]     dfile     = new byte[openfile.Length];
             openfile.Read(dfile, 0, dfile.Length);
             openfile.Close();
             dfile = decrypter.Decode(dfile);
             string text = Encoding.ASCII.GetString(dfile);
             Clipboard.SetText(text);
             MessageBox.Show("Password: "******"\nPassword been copied to the clipboard.", "Decrypted", MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.Close();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         MessageBox.Show("Password don't match", "Info", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }