Decryption in .NET application,automate passPhrase

syousuf shahbaz.bhat at
Sun Feb 15 13:47:57 CET 2009

I am working on decryting a pgp file using GnuPG.I want to do the same in a
.NET C# Console Application.I want to send the passPhrase from the
application itself,& don't want it to prompt.
I tried to passing the Passphrase from the application but its not working.

Finally,I want to decrypt the file,stream the dataout.My code is below.If
you can kindly help me on this.
Here i have to manually put the passphrase & then i get the data stream in
the Temp string variable.

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Threading; // for Thread class

namespace ConsoleApplication3
class Program
static void Main(string[] args)

string passphrase = “$Trans at RtA09″;

Process myProcess = new Process();
StreamWriter sw;
StreamReader sr;
StreamReader err;

ProcessStartInfo myProcessStartInfo = new
myProcessStartInfo.Arguments = “–decrypt C:/Transfer/test.gpg”;
myProcessStartInfo.RedirectStandardError = true;
myProcessStartInfo.RedirectStandardInput = true;
myProcessStartInfo.RedirectStandardOutput = true;
myProcessStartInfo.UseShellExecute = false;

myProcess.StartInfo = myProcessStartInfo;

sw = myProcess.StandardInput;
sr = myProcess.StandardOutput;
err = myProcess.StandardError;

sw.AutoFlush = true;
if (passphrase != null && passphrase != “”)//
{                                                       //Here i am passing
the passphrase,but it doesnot write in
sw.WriteLine(passphrase);                     //
}                                                         //

String Temp = sr.ReadToEnd();
Temp += err.ReadToEnd();


Any help,will be highly appreciated.
Kind regards.
View this message in context:
Sent from the GnuPG - User mailing list archive at

More information about the Gnupg-users mailing list