简体   繁体   中英

Converting ASCII file to UTF8

I'm working on an encryption program that passes the text to ASCII and then decrypts for normal text again. The problem is that the decryption, the accents and special characters do not appear. I can not at all (tenteri various codes) convert it to UTF8.

Detail of a file is being generated to store these encryptions and descriptografias.

Here is the code below (not working at all!):

        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();

也许您应该改为编码和解码字节,而不是字符。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM