jstylez
jstylez

Reputation: 11

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 = 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();

Upvotes: 0

Views: 1981

Answers (1)

Justin C
Justin C

Reputation: 777

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...

Upvotes: 2

Related Questions