Pergunta

I've been tasked with decrypting pgp files retrieved from various FTP sites. We have GNUPG installed on the server. I've evaluated Bouncy Castle and StarkSoft as well. I'm not really wanting to purchase commercial decryption software. Thus, I'm seeking ways to use either Bouncy Castle or something within the .NET Framework 4.5 itself to accomplish this decryption task. If you've decrypted pgp files using GNUPG, please share a link to your blog post or provide some insight as to your approach.

Foi útil?

Solução

There are two flavors common flavors of GPG, one requires --passphrase-fd 0 on the command line to tell it to read the passphrase from the standard input the other does not, I forget which version needs it, but it is obscure in the docs IIRC.

Everything is is just invoking the subprocess correctly. Here is a clip from one of my prog that does this.

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;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top