调用时.exe进程未从C#应用程序运行 [英] .exe processes are not running from a C# application when called

查看:136
本文介绍了调用时.exe进程未从C#应用程序运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个应用程序,除其他外,它使用GpgApi解密文件.我在C#中使用GpgApi对该文件进行了如下解密:

I wrote an app that, among other things, decrypts a file using GpgApi. I used GpgApi in C# to decrypt the file as follows:

 GpgInterface.ExePath = @"C:\Program Files (x86)\GNU\GnuPG\gpg.exe";

 GpgDecrypt decrypt = new GpgDecrypt(encryptedFile, file);
 decrypt.AskPassphrase = GetPassword;
 { 
    GpgInterfaceResult result = decrypt.Execute();
    Callback(result);
 }

我还从 https://www.gnupg.org/download/安装了gpg classic,服务器中已经存在公钥和私钥.

I also installed gpg classic from https://www.gnupg.org/download/, and the public and private keys already exist in the server.

现在,该应用程序可以在我的开发机上完美运行.它解密文件并将数据上传到数据库服务器.

Now, the application works flawlessy in my dev machine. It decrypts the file and uploads the data to the database server.

但是,当我在服务器中运行代码时,出现以下错误:

However, when I run the code in the server, I get the following error:

at GpgApi.GpgInterface.<Execute>b__e(Object sender, EventArgs args) at System.Diagnostics.Process.RaiseOnExited() at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(Object state, Boolean timedOut)

at GpgApi.GpgInterface.<Execute>b__e(Object sender, EventArgs args) at System.Diagnostics.Process.RaiseOnExited() at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(Object state, Boolean timedOut)

我不确定这是什么意思,服务器具有公钥和私钥,并且已安装gpg经典版(与我的开发机上安装的版本相同,且路径相同).另外,当我使用命令提示符运行gpg --decrypt时,它会解密文件而没有任何问题. bin文件夹中还提供了GpgApi.dll.该应用程序实际上是WCF服务库.知道我做错了什么吗?

I'm not sure what it means, the server has the public and private keys, and the gpg classic (the same version that's installed on my dev machine in the same path) is installed. Also, when I run the gpg --decrypt using command prompt, it decrypts the file without any issue. The GpgApi.dll is also provided in the bin folder. The application is actually a WCF service library. Any idea what I could be doing wrong?

IIS应用程序中的wcf服务包含所有必需的.dll.除Gpg解密外,其他所有功能均有效.

The wcf service in the IIS application contains all the required .dlls. Everything else works except for Gpg decrypt.

这是事件查看器中的内容:

This is what I have in Event Viewer:

Application: 61ReportsDecryptService.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
Stack:
   at GpgApi.GpgInterface.<Execute>b__e(System.Object, System.EventArgs)
   at System.Diagnostics.Process.OnExited()
   at System.Diagnostics.Process.RaiseOnExited()
   at System.Diagnostics.Process.CompletionCallback(System.Object, Boolean)
   at System.Threading._ThreadPoolWaitOrTimerCallback.WaitOrTimerCallback_Context(System.Object, Boolean)
   at System.Threading._ThreadPoolWaitOrTimerCallback.WaitOrTimerCallback_Context_f(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(System.Object, Boolean)

我检查了文件许可权,甚至授予了所有人"对该文件夹的完全控制权.那没用.

I checked for the file permission and even gave "Everyone" full control on the folder. That didn't work.

然后我删除了GpgApi,并启动了cmd进程来解密文件.那也不起作用.上面的事件查看器是当我使用GpgApi时.这是我用于解密的代码.

I then removed GpgApi, and started cmd process to decrypt the file. That didn't work either. The event viewer above is when I used GpgApi. Here's the code I used for decrypting.

    string encryptedFile = dataFileLocation + filename;
    filename = filename.ToString().Substring(0, filename.ToString().IndexOf(".gpg")).ToString();
    string file = dataFileLocation + filename; //@"C:\MMS\Data\" + filename + ".mdb";
    string sCommandLine = "C:\\Program Files (x86)\\GNU\\GnuPG\\gpg.exe --passphrase password --output \"" + file + "\" --decrypt \"" + encryptedFile + "\"";

    this.WriteToFile("starting command line decryption");

    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"cmd.exe");
    psi.CreateNoWindow = true;
    psi.UseShellExecute = false;
    psi.RedirectStandardOutput = true;
    psi.RedirectStandardInput = true;
    psi.RedirectStandardError = true;
    psi.WorkingDirectory = @"C:\Program Files (x86)\GNU\GnuPG";

    System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi);

    string cmdLine = @"gpg.exe --passphrase-fd 0 -o C:\MMS\Data\test.mdb --decrypt C:\MMS\Data\filename.gpg";

    process.StandardInput.WriteLine(cmdLine);
    process.StandardInput.Flush();
    process.StandardInput.Close();
    process.WaitForExit();
    process.Close();

但是由于某种原因,它根本无法运行.即使我不提供密码,或者密码错误,它也不会告诉我.它根本什么也没做.我什至在try-catch块中添加了它,但从未触发过异常.如果我将上面的gpg.exe命令复制粘贴到命令提示符下,则它可以工作,但是从C#中执行任何操作后都不会执行任何操作.我还有什么其他选择?

But for some reason it doesn't run at all. It doesn't tell me even if I don't supply the password, or if the password is wrong. It just doesn't do anything at all. I even had it in try-catch block, the exception never fired. If I copy-paste the above gpg.exe command to command prompt, then it works, but doesn't do anything when done from C#. What other options do I have left?

推荐答案

我在使用GpgApi解密文件时遇到了同样的问题.似乎该库的设计欠佳.

I had the same issue with decrypting files using GpgApi. It looks like this library isn't well-designed.

最后,我使用了 PgpSharp 而不是GpgApi,它工作正常.

Finally I've used PgpSharp instead of GpgApi and it works fine.

这篇关于调用时.exe进程未从C#应用程序运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆