Decrypting files with PGP and C#
My problem is when the command line runs it doesn't add anything in my decrypt text file. I added text to the decrypt.txt file to see if it writes to it and it does because the text gets deleted.
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo("cmd.exe");
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError 开发者_如何学Go= true;
psi.WorkingDirectory = "c:\\";
System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi);
string sCommandLine = "echo femme toxin sorghum| gpg.exe --batch --passphrase-fd 0 --decrypt E:\\entemp.txt > E:\\detemp.txt";
process.StandardInput.WriteLine(sCommandLine);
process.StandardInput.Flush();
process.StandardInput.Close();
process.WaitForExit();
process.Close();
i've been doing a lot of gpg.exe stuff lately...
i think you are redirecting your gpg command standard out to your file...
you may want something more like this
echo password123|gpg.exe --yes --batch --passphrase-fd 0 --decrypt --output c:\file.txt c:\file.gpg
you could also call gpg.exe directly in your process instead of calling cmd and then passing a command...if you do that though, you'll nix the "echo" stuff and add --yes ... c:\file.gpg
and so on to an arguments property. then...your first input will be like gpgProc.standardinput.writeline(password123);
this method also gives you the ability to get standard error output and process exit codes for gpg.exe directly instead of cmd.exe exit code, etc.
perhaps that will help...
精彩评论