2013-10-31 30 views
0

我的任務是解密從各個FTP站點檢索到的pgp文件。我們在服務器上安裝了GNUPG。我也評估過Bouncy Castle和StarkSoft。我並不是真的想購買商業解密軟件。因此,我正在尋求使用Bouncy Castle或.NET Framework 4.5內部的某些方法來完成此解密任務的方法。如果您使用GNUPG解密了pgp文件,請分享您的博客文章鏈接或提供一些關於您的apporach的信息。C#中的GNUPG解密#

非常感謝您的幫助和指導。

+0

[相關問題:GnuPG的包裝用C#(http://stackoverflow.com/questions/1214026/gnupg-wrapper-with-c-sharp) – Mike

+0

不知道爲什麼,這個問題被賦予了-1?試圖將其作爲一個問題來形容,並認爲我的工作重點很好? – SidC

回答

1

GPG有兩種口味的通用口味,一種口令需要在命令行上使用--passphrase-fd 0來告訴它從標準輸入讀取口令,另一種口令不會,我忘記了哪個版本需要它,但它在文件IIRC中是不明確的。

一切都是正確調用子進程。這是來自我的編程之一,這是一個剪輯。

private string GPGEncrypt(string src) 
{ 
    FileInfo fi = new FileInfo(src); 
    string OutputName = GetEncryptedName(src); 
    if (File.Exists(OutputName)) 
    { 
    if (!chkOverwrite.Checked) 
    { 
     SetStatus("Output file already exists - " + OutputName); 
     return ""; 
    } 
    } 

    string path = fi.DirectoryName; 

    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(props.PGPExecutable); 
    psi.CreateNoWindow = true; 
    psi.UseShellExecute = false; 
    psi.RedirectStandardError = true; 
    psi.RedirectStandardInput = true; 
    psi.RedirectStandardOutput = true; 
    psi.WorkingDirectory = Path.GetDirectoryName(props.PGPExecutable); 

    string args = string.Format(
    " --encrypt --recipient {0} --output \"{1}\" \"{2}\"" 
    , txtEncryptID.Text.Trim() // 1 
    , OutputName // 2 
    , src // 3 
); 

    txtCommandLine.Text = args; 

    psi.Arguments = args; 

    System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi); 
    // process.StandardInput.WriteLine(CommandLine); 
    // process.StandardInput.Flush(); 
    // process.StandardInput.Close(); 
    process.WaitForExit(); 
    int rc = process.ExitCode; 
    process.Close(); 

    txtCommandLine.Text = string.Format("{0} exited with return code {1},", Path.GetFileName(props.PGPExecutable), rc); 

    return OutputName; 
}