GPG错误用法:GPG [options] [filename] during GPG——decrypt



我尝试使用GPG命令解密我的文件:

        FileInfo info = new FileInfo(@"C:Users***Desktopfilesfile.pgp");
        string decryptedFileName = info.FullName.Substring(0, info.FullName.LastIndexOf('.')) + "Dec.TXT";
        string encryptedFileName = info.FullName;
        string password = "pass";
        System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");
        psi.CreateNoWindow = true;
        psi.UseShellExecute = false;
        psi.RedirectStandardInput = true;
        psi.RedirectStandardOutput = true;
        psi.RedirectStandardError = true;
        psi.WorkingDirectory = @"C:Program Files (x86)GNUGnuPG";
        System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi);
        //string sCommandLine = @"echo " + password + "|gpg.exe --passphrase-fd 0 --batch --verbose --yes --output " + decryptedFileName + @" --decrypt """ + encryptedFileName;
        string sCommandLine = @"gpg --output " + decryptedFileName + @" --decrypt """ + encryptedFileName;
        process.StandardInput.WriteLine(sCommandLine);
        process.StandardInput.Flush();
        process.StandardInput.Close();
        process.WaitForExit();
        string result = process.StandardOutput.ReadToEnd();
        string error = process.StandardError.ReadToEnd();
        process.Close(); 

不幸的是,我得到以下错误:"usage: gpg [options] [filename]rn"你知道哪里出错了吗?

传递的参数错误。两个字符串中有一个未设置,或者特殊字符的转义有问题。

Dump sCommandLine(或在那里添加调试器断点),可能两个文件名中的一个为空或严重转义。这将很容易帮助您找到导致问题的变量。

您可能还想考虑使用像BouncyCastle这样的本地OpenPGP库,而不是从c#调用GnuPG二进制文件。

最新更新