[英]GPG encryption is working in console debug mode but not in release mode( window service)
我正在使用gpg(GnuPG)将.csv文件加密为.gpg文件。 以下代码是在调试模式下生成加密文件的。 当我在Windows服务下安装时,将引发异常。 “ gpg:<> C:\\ emp.csv:已跳过:无公共密钥gpg:[stdin]:加密失败:无公共密钥”。 当我在调试模式(例如“ 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());
GnuPG管理每个用户的GnuPG主目录。 如果您以本地用户身份(在开发/调试时)导入密钥,则密钥将被导入到本地用户的主目录中。 如果以后将其作为系统服务运行,则定义为服务所有者的用户可能是另一个用户,并且无法访问本地用户的主目录。
可能的解决方案:
GNUPGHOME
环境变量或--homedir
参数为您的应用程序定义一个固定的主目录。 请注意,默认情况下,GnuPG对文件夹的权限比较挑剔,并且如果您不太确定其含义,请不要对此进行任何更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.