質問

I have a web application built with C# that creates a txt file based on user input information. This txt file is then converted to PGP in the application via a command line tool.

If a user enters international characters, they are changed when the PGP file is decrypted.
For example. If the user enters: "ó" it is converted to "ó" after I decrypt the PGP.

The txt file that is created has the correct characters in it, but when converted back to txt it does not. I imagine that this is an encoding issue, but I am not sure what to try.

This is what my code looks like:

//Create the text file
            using (StreamWriter sw = File.CreateText(filePath + fileName)) //Create text file 
            {
                sw.Write(bodyText); //Add body text to text file.
            }
//PGP Encrypt
            using (Process cmd = new Process()) //Open the pgp command line tool and start it using the arguments.
            {
                cmd.StartInfo.WorkingDirectory = "C:\\Program Files\\PGP Corporation\\PGP Command Line\\";
                cmd.StartInfo.UseShellExecute = false;
                cmd.StartInfo.FileName = "pgp.exe";
                cmd.StartInfo.Arguments = arguments;
                cmd.StartInfo.CreateNoWindow = true;
                cmd.StartInfo.RedirectStandardInput = true;
                cmd.StartInfo.RedirectStandardOutput = true;
                cmd.StartInfo.RedirectStandardError = true;
                cmd.Start();
                cmd.WaitForExit();
                cmd.Close();
            }
役に立ちましたか?

解決

Edit: Actually it makes more sense to me that sw.Write writes a file with a BOM, but PGP decrypt might not, so if you're opening with notepad that will default to Windows-1252 when there is no BOM? If that is the case, you can try reading the decrypted file with C# and specify a the encoding as UTF8 when you open it.

The à character I find usually comes from Windows-1252 Encoding.GetEncoding(1252) being interpreted as UTF8, or vice versa. Some older programs will use it by default, or from web sources, so the problem might be farther up than your PGP encryption.

Try writing the file as Windows-1252 (maybe PGP actually defaults to that on windows), or make sure that when you write out the file it has a BOM for UTF8

他のヒント

It seems your PGP decryption tool interprets the file as encoded in UTF-8. So try to write the file UTF-8 encoded

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top