string arguments = "--passphrase-fd 0 " + " --output " + outputName + " --decrypt --pinentry-mode=loopback --passphrase=YourPassphrase " + inputName;
I was trying to run GPG.exe from C# language but not able to get expected output
Hi all,
Trying to run a GPG decryption command from within C# but getting no output. C# Code is...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace GPGproject
{
class Program
{
public static void Main()
{
DecryptFile();
}
public static void DecryptFile()
{
string outputName = @"E:\GPGTest\testdecrypt26.txt";
string inputName = @"E:\GPGTest\sampletest.pgp";
string gpgHomeDir = @"C:\Program Files (x86)\GnuPG\bin";
string arguments = "--homedir \"" + gpgHomeDir + "\" --passphrase-fd 0 " + " --output " + outputName + " --decrypt " + inputName;
string path = @"C:\Program Files (x86)\GnuPG\bin\gpg.exe";
var procStartInfo = new ProcessStartInfo(path, arguments)
{
WorkingDirectory = gpgHomeDir,
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true
};
var proc = new Process { StartInfo = procStartInfo };
proc.Start();
proc.StandardInput.WriteLine("passphrasetest1");
proc.StandardInput.Flush();
string result = proc.StandardOutput.ReadToEnd();
string error = proc.StandardError.ReadToEnd();
Console.WriteLine(result);
Console.WriteLine(error);
}
}
}
If I use the following arguments then I got this error :
string arguments = "--homedir \"" + gpgHomeDir + "\" --passphrase-fd 0 " + " --output " + outputName + " --decrypt " + inputName;
gpg: encrypted with RSA key, ID EB7CAC8D8297712C
gpg: decryption failed: No secret key
Or if I use the following arguments then I got pop up for passphrase, i dont want to enter passphrase from pop up, i only want to pass passphrase from program :
string arguments = "--passphrase-fd 0 " + " --output " + outputName + " --decrypt " + inputName;
]1
Please suggest to me where I did wrong code to pass passphrase from program