private void btnEncrypt_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Public Keys (*.xml)|*.xml"; if (openFileDialog.ShowDialog() == DialogResult.OK) { Stream temp = openFileDialog.OpenFile(); String publicKeyXml = new StreamReader(temp).ReadToEnd(); byte[] encryptedData = EncryptionClass.EncryptText(tbMessage.Text, publicKeyXml); tbResult.Text = Convert.ToBase64String(encryptedData); tbMessage.Clear(); tbMessage.Text = tbResult.Text; tbResult.Clear(); } }