コード例 #1
0
        private void Button_FindFile_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            if (fileDialog.ShowDialog() == true)
            {
                Label_FilePath.Content = fileDialog.FileName;
            }
            else
            {
                return;
            }

            FileInfo infoFile = new FileInfo((string)Label_FilePath.Content);

            _userFile = new byte[infoFile.Length];

            using (BinaryReader strReader = new BinaryReader(File.Open((string)Label_FilePath.Content, FileMode.Open), Encoding.UTF8))
            {
                strReader.Read(_userFile, 0, _userFile.Length);
            }

            MyConsole.AppendText("Считал файл (весом в " + _userFile.Length + " байт):\n");
            MyConsole.AppendText(Label_FilePath.Content + "\n");
        }
コード例 #2
0
        private void CipherFile_Click(object sender, RoutedEventArgs e)
        {
            if ((_userFile == null) || (_userFile.Length == 0))
            {
                MyConsole.AppendText("Ошибка! Файл пуст или вы забыли его считать\n");
                return;
            }
            if (UserKey.Password.Length == 0)
            {
                MyConsole.AppendText("Ошибка! Не ввели пароль\n");
                return;
            }

            int textLength = Convert.ToInt32(ComboBox_RijndailTextLength.Text);
            int keyLength  = Convert.ToInt32(ComboBox_RijndailKeyLength.Text);

            Rijndail des = new Rijndail(textLength, keyLength);
            TimeSpan tms = new TimeSpan();

            switch (ComboBox_ModeDes.SelectedIndex)
            {
            case 0:     // ECB
                _userFile = des.ECB_Encrypt(_userFile, Encoding.UTF8.GetBytes(UserKey.Password.ToString()), out tms);
                break;

            case 1:     // CBC
                break;

            case 2:     // OFB
                break;

            case 3:     // CFB
                break;

            default:
                break;
            }
            MyConsole.AppendText("Зашифровал файл (время шифрования " + tms.ToString() + "):\n");
            MyConsole.AppendText(Label_FilePath.Content + "\n");

            using (BinaryWriter strWr = new BinaryWriter(File.Open((string)Label_FilePath.Content, FileMode.Create), Encoding.UTF8))
            {
                strWr.Write(_userFile, 0, _userFile.Length);
                strWr.Flush();
            }

            MyConsole.AppendText("Сохранил результат\n");

            _userFile = new byte[0];
            Label_FilePath.Content = "-";
        }
コード例 #3
0
 private void AppendInConsoleLine(string text)
 {
     MyConsole.AppendText(text + "\n");
 }