将ASCII文件转换为UTF8

时间:2015-06-23 21:00:45

标签: c# encryption utf-8

我正在开发一个加密程序,将文本传递给ASCII,然后再次解密普通文本。问题是解密,重音和特殊字符不会出现。我根本不能(tenteri各种代码)将其转换为UTF8。

正在生成文件的详细信息以存储这些加密和描述文件。

以下是以下代码(根本不用!):

        StreamWriter criptografia = new StreamWriter(@"ItensCriptografados.txt", true);
        string palavras = txtcripto.Text;
        txtdescripto.Text = "";
       UTF7Encoding descript = new UTF7Encoding();



        for (int i = 0; i < palavras.Length; i +=3)
        {
            char oi = char.Parse(palavras.Substring(i, 3));
            if (palavras.Substring(i, 3) == "341"){
                i += 3;
                byte[] bytes2 = BitConverter.GetBytes(oi);
                byte[] convertido = Encoding.UTF8.GetBytes(oi);
                byte[] utf8Array = Encoding.Convert(Encoding.ASCII, Encoding.UTF7, bytes2);
                string s2 = descript.GetString(utf8Array);
            //string s2 = Encoding.UTF7.GetString(bytes2);

               UTF8Encoding utf = new UTF8Encoding();
                byte[] byteArray = Encoding.ASCII.GetBytes(s);
                byte[] utfArray = Encoding.Convert(Encoding.ASCII, Encoding.UTF8, byteArray);
                string finalString = utf.GetString(utfArray);
            txtdescripto.Text = txtdescripto.Text + s2.ToString();
        }

        }
        criptografia.WriteLine("Texto:{0} . Criptografado:{1}",txtdescripto.Text.ToString(), palavras.ToString());
        criptografia.Close();

1 个答案:

答案 0 :(得分:1)

也许您应该对字节进行编码和解码,而不是字符。