Некорректное отображение кириллицы при чтении txt файла - C#
Формулировка задачи:
Реализую алгоритм шифрования DES. При выводе в textbox не отображаются русские символы. Текстовый файл в формате юникод.
Кнопка шифровать
Кнопка дешифровать
string key = textBox3.Text;
string line = textBox4.Text;
FileStream stream = new FileStream("D:\\test.txt", FileMode.OpenOrCreate,FileAccess.Write);
DESCryptoServiceProvider cryptic = new DESCryptoServiceProvider();
cryptic.Key = ASCIIEncoding.ASCII.GetBytes(key);
cryptic.IV = ASCIIEncoding.ASCII.GetBytes(key);
CryptoStream crStream = new CryptoStream(stream,
cryptic.CreateEncryptor(),CryptoStreamMode.Write);
byte[] data = ASCIIEncoding.ASCII.GetBytes(line);
crStream.Write(data,0,data.Length);
crStream.Close();
stream.Close();
string text = System.IO.File.ReadAllText(@"D:\\test.txt");
textBox1.Text = text.ToString();string key = textBox3.Text;
FileStream stream = new FileStream("D:\\test.txt", FileMode.Open,FileAccess.Read);
DESCryptoServiceProvider cryptic = new DESCryptoServiceProvider();
cryptic.Key = ASCIIEncoding.ASCII.GetBytes(key);
cryptic.IV = ASCIIEncoding.ASCII.GetBytes(key);
CryptoStream crStream = new CryptoStream(stream,
cryptic.CreateDecryptor(),CryptoStreamMode.Read);
StreamReader reader = new StreamReader(crStream);
string data = reader.ReadToEnd();
textBox1.Text = data;
reader.Close();
stream.Close();Решение задачи: «Некорректное отображение кириллицы при чтении txt файла»
textual
Листинг программы
byte[] data = Encoding.UTF8.GetBytes(line);