'PGP decryption command not outputting file - process.StandardInput.WriteLine(sCommandLine);
public string DecryptFile(string encryptedFilePath)
{
const string quote = "\"";
FileInfo info = new FileInfo(encryptedFilePath);
string decryptedFileName = info.FullName.Substring(0, info.FullName.IndexOf(".pgp") + 4);
//decryptedFileName = info.FullName.Replace(".pgp", "");
decryptedFileName = decryptedFileName.Replace(this.txtFolderPath, this.txtFolderPath + "\\ProcessedZip\\");
//decryptedFileName = "C:\\pgpTest\\ProcessedZip\\"+ info.Name;
decryptedFileName = decryptedFileName.Replace(".pgp", "");
decryptedFileName = quote + decryptedFileName + quote;
string encryptedFileName = quote + info.FullName + quote;
string password = "thisisnottherealpassword";
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 = this.txtFolderPath;
System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi);
string sCommandLine = "gpg.exe --pinentry-mode=loopback --passphrase \"" + password + "\" -d -o --batch --verbose --yes --output " + decryptedFileName + @" --decrypt " + encryptedFileName;
process.StandardInput.WriteLine(sCommandLine);
process.StandardInput.Flush();
process.StandardInput.Close();
process.WaitForExit();
//string result = process.StandardOutput.ReadToEnd();
//string error = process.StandardError.ReadToEnd();
process.Close();
return decryptedFileName;
}
The above code works in a separate project but having it utilized by another layer of the application through binaries is not spitting out a decrypted file. I'm not sure why as no errors seem to be thrown and using the commandline string in my own command line will correctly run the process.
Any thoughts on why this could be?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
