/// <summary> /// Decrypts MemoryStream using PGP. /// </summary> /// <param name="encryptedStream">MemoryStream containing data to be decrypted</param> /// <param name="privateKeyFile">Path to the private key file. Usually a .asc file.</param> /// <param name="privateKeyPassword">Password to use.</param> /// <returns>MemoryStream containing decrypted data.</returns> /// <remarks>MemoryStream containing encrypted data must be ascii armored.</remarks> public MemoryStream DecryptStream(MemoryStream encryptedStream, string privateKeyFile, string privateKeyPassword) { MemoryStream decryptedStream = new MemoryStream(); FileStream privateKeyStream = File.OpenRead(privateKeyFile); _pgp.DecryptStream(encryptedStream, privateKeyStream, privateKeyPassword, decryptedStream); return(decryptedStream); }
private void DecryptButton_Click(object sender, RoutedEventArgs e) { string encryptedmessage = new TextRange(EncryptedMessageTextbox.Document.ContentStart, EncryptedMessageTextbox.Document.ContentEnd).Text; string password = PasswordBox.Text; string privatekey = new TextRange(PrivateKeyTextbox.Document.ContentStart, PrivateKeyTextbox.Document.ContentEnd).Text; if (encryptedmessage == String.Empty) { MessageBox.Show("Keine Nachricht eingegeben"); } if (privatekey == String.Empty) { MessageBox.Show("Keinen Private Key eingegeben"); } PGPLib pGPLib = new PGPLib(); MemoryStream decrypted = new MemoryStream(); using (MemoryStream encryptedmessagestream = new MemoryStream(Encoding.UTF8.GetBytes(encryptedmessage))) { using (MemoryStream privatekeystream = new MemoryStream(Encoding.UTF8.GetBytes(privatekey))) { string test = pGPLib.DecryptStream(encryptedmessagestream, privatekeystream, password, decrypted); decrypted = new MemoryStream(decrypted.ToArray()); StreamReader streamReader = new StreamReader(decrypted); string decryptedtext = streamReader.ReadToEnd(); DecryptedMessageBox.Text = ""; DecryptedMessageBox.Text = decryptedtext; } } }