private void btnGiaiMa_Click(object sender, EventArgs e) { if (txt_url_input.Text.Length != 0) { try { byte[] filecontent = File.ReadAllBytes(txt_url_input.Text); //txt_plaintext.Text = FileFactory.DecryptAES(txt_input.Text, txt_key.Text); //txt_plaintext.Text = FileFactory.DecryptAES(txt_input.Text, txt_key.Text); //StreamWriter sw = new StreamWriter(txt_url_plaintext.Text, false, Encoding.UTF8); //sw.WriteLine(txt_plaintext.Text); //sw.Close(); string fileExt = Path.GetExtension(txt_url_input.Text); SaveFileDialog sd = new SaveFileDialog(); sd.Filter = "File (*" + fileExt + ")|*" + fileExt; if (sd.ShowDialog() == DialogResult.OK) { if (radioButtonAES.Checked == true) { File.WriteAllBytes(sd.FileName, FileFactory.DecryptAES(filecontent, txt_key.Text)); } else { File.WriteAllBytes(sd.FileName, FileFactoryDES.DecryptDES(filecontent, txt_key.Text)); } txt_key.Enabled = true; } } catch { MessageBox.Show("Không giải mã được, hãy kiểm tra lại khóa"); } } else { MessageBox.Show("Mời bạn chọn file"); } }
private void btnMaHoa_Click(object sender, EventArgs e) { if (txt_key.Text.Length != 0 && txt_url_input.Text.Length != 0) { //Console.Write(txt_ciphertext.Text); byte[] filecontent = File.ReadAllBytes(txt_url_input.Text); //txt_ciphertext.Text = FileFactory.EncryptAES(txt_input.Text, txt_key.Text); //txt_ciphertext.Text = FileFactory.EncryptAES(filecontent, txt_key.Text); //StreamWriter sw = new StreamWriter(txt_url_ciphertext.Text, false, Encoding.UTF8); //sw.WriteLine(txt_ciphertext.Text); //sw.Close(); string fileExt = Path.GetExtension(txt_url_input.Text); SaveFileDialog sd = new SaveFileDialog(); sd.Filter = "File (*" + fileExt + ")|*" + fileExt; if (sd.ShowDialog() == DialogResult.OK) { if (radioButtonAES.Checked == true) { File.WriteAllBytes(sd.FileName, FileFactory.EncryptAES(filecontent, txt_key.Text)); } else { File.WriteAllBytes(sd.FileName, FileFactoryDES.EncryptDES(filecontent, txt_key.Text)); } txt_key.Enabled = true; } } else if (txt_key.Text.Length == 0) { MessageBox.Show("Mời bạn nhập key"); } else { MessageBox.Show("Mời bạn chọn file"); } }