0

I need to write a C# program for the encrypting and decrypting of files with PGP. I can't seem to find adequate resources in the Internet. Can someone maybe help?

3
Contributors
2
Replies
17
Views
6 Years
Discussion Span
Last Post by Angel Armando
0

Try this, I did it this way and it worked wonders, in this link you will find more details.

http://www.systemdeveloper.info/2013/11/decrypt-files-encrypted-with-gnupg-from.html

public static string DecryptFile(string encryptedFilePath)
        {
            FileInfo info = new FileInfo(encryptedFilePath);
            string decryptedFileName = info.FullName.Substring(0, info.FullName.LastIndexOf('.')) + "Dec.TXT";
            string encryptedFileName = info.FullName;

            string password = System.Configuration.ConfigurationManager.AppSettings["passphrase"].ToString();

            System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");

            psi.CreateNoWindow = true;
            psi.UseShellExecute = false;
            psi.RedirectStandardInput = true;
            psi.RedirectStandardOutput = true;
            psi.RedirectStandardError = true;
            psi.WorkingDirectory = @System.Configuration.ConfigurationManager.AppSettings["WorkingDirectory"].ToString();

            System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi);
            string sCommandLine = @"echo " + password + "|gpg.exe --passphrase-fd 0 --batch --verbose --yes --output " + decryptedFileName + @" --decrypt " + encryptedFileName;

            process.StandardInput.WriteLine(sCommandLine);
            process.StandardInput.Flush();
            process.StandardInput.Close();
            process.WaitForExit();
            //string result = process.StandardOutput.ReadToEnd();
            //string error = process.StandardError.ReadToEnd();
            process.Close();
            return decryptedFileName;
        }

Edited by Angel Armando: the previous post was in Spanish

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.