private void DesencriptarButton_Click(object sender, EventArgs e) { OpenFileDialog od = new OpenFileDialog(); od.Filter = "Archivos Xml (*.xml)|*.xml"; od.InitialDirectory = Application.StartupPath; if (od.ShowDialog() == DialogResult.OK) { Stream temporal = od.OpenFile(); string clavePrivadaXml = new StreamReader(temporal).ReadToEnd(); byte[] datosDesencriptados = ClaseEncriptacion.DesencriptarTexto(this.MensajeTextBox.Text, clavePrivadaXml); var temp = Encoding.ASCII.GetString(datosDesencriptados); this.ResultadoTextBox.Text = temp; } }
private void GenerarClaveButton_Click(object sender, EventArgs e) { ClaseEncriptacion crypto = new ClaseEncriptacion(); FolderBrowserDialog f = new FolderBrowserDialog(); f.SelectedPath = Application.StartupPath; if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string carpeta = f.SelectedPath; FileStream fichero = new FileStream(Path.Combine(carpeta, "ClavePublic.xml"), FileMode.Create, FileAccess.Write); byte[] clavePublica = crypto.CrearClavesPublicas(); fichero.Write(clavePublica, 0, clavePublica.Length); fichero.Close(); fichero = new FileStream(Path.Combine(carpeta, "ClavePrivate.xml"), FileMode.Create, FileAccess.Write); byte[] clavePrivada = crypto.CrearClavesPrivadas(); fichero.Write(clavePrivada, 0, clavePrivada.Length); fichero.Close(); MessageBox.Show("Claves Almacenadas corrextamente"); } }