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?

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


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;

            //string result = process.StandardOutput.ReadToEnd();
            //string error = process.StandardError.ReadToEnd();
            return decryptedFileName;

Edited 3 Years Ago by Angel Armando: the previous post was in Spanish

This article has been dead for over six months. Start a new discussion instead.