我正在使用 gpg(GnuPG) 将 .csv 文件加密为 .gpg 文件。下面的代码是在调试模式下生成加密文件。当我在 Windows 服务下安装时,它会抛出异常。“gpg: <>C:\emp.csv: 跳过: 没有公钥 gpg: [stdin]: 加密失败: 没有公钥”。当我在“consoleapp.exe -c”等调试模式下运行服务时,它的工作原理</p>
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());