예제 #1
0
        private void buttonEncode_Click(object sender, EventArgs e)
        {
            string inputPath  = textBoxInput.Text;
            string outputPath = textBoxOutput.Text;

            if (textBox1.Text.Trim() == "")
            {
                MessageBox.Show(new Form()
                {
                    TopMost = true
                },
                                "Введите парольную фразу для шифрования!",
                                "Ошибка!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            else
            if (!File.Exists(inputPath))
            {
                MessageBox.Show(new Form()
                {
                    TopMost = true
                },
                                "Данного входного файла не существует!",
                                "Ошибка!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            else
            if (outputPath == "")
            {
                MessageBox.Show(new Form()
                {
                    TopMost = true
                },
                                "Отсутствует файл для вывода!",
                                "Ошибка",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            else
            {
                int longtoEncode;

                if (radioButton1.Checked)
                {
                    longtoEncode = 128;
                }

                else
                if (radioButton2.Checked)
                {
                    longtoEncode = 192;
                }
                else
                {
                    longtoEncode = 256;
                }

                byte[] userKeyBytes = Encoding.Unicode.GetBytes(textBox1.Text);
                PasswordDeriveBytes passwordDeriveBytes = new PasswordDeriveBytes(userKeyBytes, null);
                byte[] passInByte = passwordDeriveBytes.GetBytes(longtoEncode);


                #region endcodeFile
                RC6 rc6 = new RC6(longtoEncode, passInByte);

                byte[] inputBytes = File.ReadAllBytes(inputPath);
                byte[] codedText  = rc6.EncodeRc6(inputBytes);

                File.WriteAllBytes(outputPath, codedText);
                #endregion
            }
        }
예제 #2
0
        private void buttonEncodeToFile_Click(object sender, EventArgs e)
        {
            if (textBox2.Text.Trim() == "")
            {
                MessageBox.Show(new Form()
                {
                    TopMost = true
                },
                                "Введите парольную фразу для шифрования!",
                                "Ошибка!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            else
            if (textBox1.Text.Trim() == "")
            {
                MessageBox.Show(new Form()
                {
                    TopMost = true
                },
                                "Введите текст для кодирования!",
                                "Ошибка!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            else
            {
                int longtoEncode;

                if (radioButton1.Checked)
                {
                    longtoEncode = 128;
                }

                else
                if (radioButton2.Checked)
                {
                    longtoEncode = 192;
                }
                else
                {
                    longtoEncode = 256;
                }

                //String userKeyword = textBox2.Text.Length < maxLength ? textBox2.Text+ new string(' ', maxLength-textBox2.Text.Length): textBox2.Text;

                byte[] userKeyBytes = Encoding.Unicode.GetBytes(textBox2.Text);
                PasswordDeriveBytes passwordDeriveBytes = new PasswordDeriveBytes(userKeyBytes, null);
                byte[] passInByte = passwordDeriveBytes.GetBytes(longtoEncode);

                RC6 rc6 = new RC6(longtoEncode, passInByte);

                byte[] codedText = rc6.EncodeRc6(textBox1.Text);

                //textBox2.Text=Encoding.UTF8.GetString(rc6.DecodeRc6(codedText));


                #region codeToFile
                SaveFileDialog s = new SaveFileDialog();
                s.CheckPathExists = true;
                s.SupportMultiDottedExtensions = true;
                s.Title = "Выберите файл для сохранения кодированного текста";
                if (s.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                File.WriteAllBytes(s.FileName, codedText);
                #endregion
            }
        }