I'd like to write an application which would encrypt a file using GnuPG.
It would be a Windows Application which would run a GnuPG as a Console Application.
I found this code but it doesn't work properly.
http://www.codeproject.com/KB/security/gnupgdotnet.aspx
On the basis of this application I wrote a simple console application with some adjustments.
Expand|Select|Wrap|Line Numbers
- public void ExecuteCommand() {
- StreamWriter sw;
- StreamReader sr;
- string gpgOptions = BuildOptions();
- string gpgExecutable = _bindirectory + "\\gpg.exe";
- // Create startinfo object
- ProcessStartInfo pInfo = new ProcessStartInfo(gpgExecutable, gpgOptions);
- pInfo.WorkingDirectory = _bindirectory;
- pInfo.CreateNoWindow = false; //true;
- pInfo.RedirectStandardInput = true;
- pInfo.RedirectStandardOutput = true;
- pInfo.UseShellExecute = false;
- _processObject = Process.Start(pInfo);
- Thread.Sleep(500);
- sw = _processObject.StandardInput;
- sr = _processObject.StandardOutput;
- sw.Write(_passphrase + Environment.NewLine);
- sw.Flush();
- sw.Write("y" + Environment.NewLine);
- sw.Flush();
- _processObject.Close();
string sBuildOptions = @" --output KALIN01_1582020_0012_08.sig --sign --encrypt --recipient KEY_ATVP_001 KALIN01_1582020_0012_08.xml";
The code actually starts the GPG.EXE but it stops at the PassPhrase. Even I try to enter the passphrase from the application it simply does nothing.
As you can see I tried with pInfo.CreateNoWindow = false; //true; Having no success.
I really have no idea how to write some text by the application using StandardInput and not manually.
Thanks for any hint.