I am using gpg(GnuPG) to encrypt .csv file to .gpg file. The below code is generate encrypted file in debug mode. When I Install under windows service it’s throwing exception. “gpg: <>C:\emp.csv: skipped: No public key gpg: [stdin]: encryption failed: No public key”. Its working when I run service in debug mode like “consoleapp.exe -c”
string arguments = string.Format(" --yes --quiet --always-trust -e -o {0} -r \"{1}\" {2}", "C:\\emp.gpg", "KeyName", "C:\\emp.csv");
ProcessStartInfo pInfo = new ProcessStartInfo( @"C:\Program Files (x86)\GNU\GnuPG\gpg2", arguments );
pInfo.WorkingDirectory = @"C:\Program Files (x86)\GNU\GnuPG\";
pInfo.CreateNoWindow = false;
pInfo.UseShellExecute = false;
pInfo.RedirectStandardInput = true;
pInfo.RedirectStandardOutput = true;
pInfo.RedirectStandardError = true;
Process process = new Process()
{
StartInfo = pInfo,
EnableRaisingEvents = true
};
process.Start();
error = process.StandardError.ReadToEnd();
agent.LogConsole(process.StandardOutput.ReadToEnd());