[英].exe processes are not running from a C# application when called
我編寫了一個應用程序,其中包括使用GpgApi解密文件的應用程序。 我在C#中使用GpgApi對該文件進行解密,如下所示:
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,並且服務器中已經存在公鑰和私鑰。
現在,該應用程序可以在我的開發機上完美運行。 它解密文件,然后將數據上傳到數據庫服務器。
但是,當我在服務器中運行代碼時,出現以下錯誤:
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 classic(與我的開發機上安裝的版本相同,且路徑相同)。 另外,當我使用命令提示符運行gpg --decrypt時,它會解密文件而沒有任何問題。 bin文件夾中還提供了GpgApi.dll。 該應用程序實際上是WCF服務庫。 知道我做錯了什么嗎?
IIS應用程序中的wcf服務包含所有必需的.dll。 除Gpg解密外,其他所有操作均有效。
編輯:
這是我在事件查看器中的功能:
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)
我檢查了文件許可權,甚至給了“所有人”對該文件夾完全控制權。 那沒用。
然后,我刪除了GpgApi,並啟動了cmd進程來解密文件。 那也不起作用。 上面的事件查看器是當我使用GpgApi時。 這是我用於解密的代碼。
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#中執行任何操作后都不會執行任何操作。 我還有什么其他選擇?
使用GpgApi解密文件時,我遇到了同樣的問題。 似乎該庫的設計欠佳。
最后,我使用了PgpSharp而不是GpgApi,它工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.