private Stream Decode(System.IO.Stream inStream) { Stream outStream = inStream; string inFile = Path.GetTempFileName(); string outFile = Path.ChangeExtension(inFile, "txt"); try { FileStreamReadWrite.DumpStreamToFile(inStream, inFile); GnuPGWrapper GPG = new GnuPGWrapper(_gnupgbindir); GnuPGCommand GPGCommand = GPG.Command; GPGCommand.Command = Commands.Decrypt; GPGCommand.InputFile = inFile; GPGCommand.OutputFile = outFile; GPGCommand.Passphrase = _passphrase; // TODO: support encrypted passphrase, no passphrase is a security risk GPG.Execute(null); outStream = FileStreamReadWrite.ReadFileToMemoryStream(outFile); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } finally { if (File.Exists(inFile)) { File.Delete(inFile); } if (File.Exists(outFile)) { File.Delete(outFile); } } return(outStream); }
private Stream Encode(Stream inStream) { Stream outStream = inStream; string inFile = Path.GetTempFileName(); string outFile = Path.ChangeExtension(inFile, "gpg"); try { FileStreamReadWrite.DumpStreamToFile(inStream, inFile); GnuPGWrapper GPG = new GnuPGWrapper(_gnupgbindir); GnuPGCommand GPGCommand = GPG.Command; GPGCommand.Command = Commands.Encrypt; GPGCommand.Recipient = _recipient; GPGCommand.Armor = true; GPGCommand.InputFile = inFile; GPGCommand.OutputFile = outFile; GPG.Execute(null); outStream = FileStreamReadWrite.ReadFileToMemoryStream(outFile); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } finally { if (File.Exists(inFile)) { File.Delete(inFile); } if (File.Exists(outFile)) { File.Delete(outFile); } } return(outStream); }