繁体   English   中英

没有密码短语的GPG解密,可在本地使用,但在IIS和托管环境上无法使用

[英]GPG decryption without passphrase, working on local but fails on IIS and hosted environment

我正在使用gpg加密解密,在本地系统上(在VS2015上运行)可以正常工作,但是当我将其托管到服务器/或尝试从本地IIS运行时,它会失败。 它不会提示任何运行时错误,但不要创建解密的文件。 这是命令:

gpg --local-user XXXXXT21XXX --output C:\Projects\myserver.api\Server_Files\input\callback_7a7ac0e3-89b1-4749-8d2a-d40cc84a27d5.xml --decrypt C:\Projects\server.api\Server_Files\Serverinput\callback_7a7ac0e3-89b1-4749-8d2a-d40cc84a27d5.asc

我用于解密的代码:

public string Decrypt(string inputFilePath, string extension = "")
        {
            try
            {
                var process = GetCmd();
                string outputFilePath = $@"{FileHelper.InputPath}\{Path.GetFileNameWithoutExtension(inputFilePath)}{extension}";

                string sCommandLine = $"{command}{string.Format(decCommand, outputFilePath, inputFilePath)}";

                process.StandardInput.WriteLine(sCommandLine);
                process.StandardInput.Flush();
                process.StandardInput.Close();
                process.WaitForExit();
                process.Close();
                return outputFilePath;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 private static System.Diagnostics.Process GetCmd()
        {
            System.Diagnostics.ProcessStartInfo psi =
                 new System.Diagnostics.ProcessStartInfo("cmd.exe");
            psi.CreateNoWindow = false;
            psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            psi.UseShellExecute = false;
            psi.RedirectStandardInput = true;
            psi.RedirectStandardOutput = true;
            psi.RedirectStandardError = true;
            psi.Verb = "runas";
            psi.WorkingDirectory = @"C:\Program Files (x86)\GnuPG\bin";

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

            return process;
        }

错误 :

System.IO.FileNotFoundException: Could not find file 'C:\Projects\Server.api\Server_Files\input\callback_7a7ac0e3-89b1-4749-8d2a-d40cc84a27d5.xml'.
    File name: 'C:\Projects\Server_if.api\Server_Files\input\callback_7a7ac0e3-89b1-4749-8d2a-d40cc84a27d5.xml'
       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
       at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
       at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)
       at System.IO.File.InternalReadAllText(String path, Encoding encoding, Boolean checkHost)
       at Server.Common.Helpers.FileHelper.ReadAllText(String path) in D:\Projects\TFT\Bitbucket_PAYDO\Server_new\Server.Common\Helpers\FileHelper.cs:line 101
       at Server.API.Controllers.ServerTransferController.<GetServerCallback>d__9.MoveNext()

如何在不提示输入密码的情况下运行gpg crypto命令?

我自己找到了答案,按照@RMH的指示,我试图为gpg找到合适的用户,在我的情况下是Administrator。 我所做的是我创建了一个自托管的Web API,并在那里尝试了相同的代码,而且令人惊讶的是它开始起作用了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM