Шифрования DES, как подлючить кириллицу? - C#

Узнай цену своей работы

Формулировка задачи:

Всем привет! Друзья вот код программы :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Security.Cryptography;

namespace DESCryptoSystem
{
    public partial class DESForm : Form
    {
        public DESForm()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                txtPathFile.Text = openFileDialog1.FileName;
            }
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            if (saveFileEncrypt.ShowDialog() == DialogResult.OK)
            {
                if (saveFileKey.ShowDialog() == DialogResult.OK)
                {
                    FileStream fs = File.Create(saveFileEncrypt.FileName);
                    DESCryptoServiceProvider dsp = new DESCryptoServiceProvider();
                    CryptoStream cs = new CryptoStream(fs, dsp.CreateEncryptor(), CryptoStreamMode.Write);
                    StreamWriter sw = new StreamWriter(cs);
                    StreamReader sr = new StreamReader(txtPathFile.Text);
                    string line = sr.ReadLine();
                    while (line != null)
                    {
                        sw.WriteLine(line);
                        line = sr.ReadLine();
                    }
                    sr.Close();
                    sw.Flush();
                    sw.Close();
                    FileStream keyFs = File.Create(saveFileKey.FileName);
                    BinaryWriter bw = new BinaryWriter(keyFs);
                    bw.Write(dsp.Key);
                    bw.Write(dsp.IV);
                    bw.Flush();
                    bw.Close();
                }
            }
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            if (openKeyFileDialog2.ShowDialog() == DialogResult.OK)
            {
                if (saveDecryptFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    FileStream keyFs = File.OpenRead(openKeyFileDialog2.FileName);
                    FileStream fsOut = File.Create(saveDecryptFileDialog1.FileName);
                    FileStream fsIn = File.OpenRead(txtPathFile.Text);
                    DESCryptoServiceProvider dsp = new DESCryptoServiceProvider();
                    BinaryReader br = new BinaryReader(keyFs);
                    dsp.Key = br.ReadBytes(8);
                    dsp.IV = br.ReadBytes(8);
                    CryptoStream cs = new CryptoStream(fsIn, dsp.CreateDecryptor(), CryptoStreamMode.Read);
                    StreamWriter sw = new StreamWriter(fsOut);
                    StreamReader sr = new StreamReader(cs);
                    sw.Write(sr.ReadToEnd());
                    sr.Close();
                    sw.Flush();
                    sw.Close();
                    fsOut.Close();
                    fsIn.Close();
                    keyFs.Close();
 
                }
 
            }
        }
    }
}
При расшифровании кирилицы т.е русс. буквы не правильно выдает начальную данные, как подключить кириллицы(или юникод) для правильного шифрование.

Решение задачи: «Шифрования DES, как подлючить кириллицу?»

textual
Листинг программы
    StreamWriter sw = new StreamWriter(cs, Encoding.UTF8);

Оцени полезность:

7   голосов , оценка 3.571 из 5