/// <summary> /// Encrypts a MemoryStream using PGP. /// </summary> /// <param name="inputStream">Stream containing data to be encrypted.</param> /// <param name="publicKeyFile">Path to the private key file. Usually a .asc file.</param> /// <returns>MemoryStream with encrypted data. It is always ascii armored.</returns> public MemoryStream EncryptStream(MemoryStream inputStream, string publicKeyFile) { MemoryStream encryptedStream = new MemoryStream(); _pgp.EncryptStream(inputStream, "input.txt", new FileInfo(publicKeyFile), encryptedStream, true); return(encryptedStream); }
private void EncryptMessageButton_Click(object sender, RoutedEventArgs e) { string publickey = new TextRange(PublicKeyBox.Document.ContentStart, PublicKeyBox.Document.ContentEnd).Text; string message = new TextRange(MessageToBeEncryptedBox.Document.ContentStart, MessageToBeEncryptedBox.Document.ContentEnd).Text; PGPLib pgp = new PGPLib(); MemoryStream encryptedmessage = new MemoryStream(); using (MemoryStream messagestream = new MemoryStream(Encoding.UTF8.GetBytes(message))) { using (MemoryStream publickeystream = new MemoryStream(Encoding.UTF8.GetBytes(publickey))) { bool ascii = true; pgp.EncryptStream(messagestream, publickeystream, encryptedmessage, ascii); encryptedmessage = new MemoryStream(encryptedmessage.ToArray()); StreamReader streamReader = new StreamReader(encryptedmessage); string encryptedtext = streamReader.ReadToEnd(); EncryptedMessageBox.Text = ""; EncryptedMessageBox.Text = encryptedtext; } } }