// защифровать файл private void button1_Click(object sender, EventArgs e) { cam(); if (check()) { OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog() == DialogResult.OK) { int i; string s, temp; string str = dialog.FileName; int len = str.Length; i = str.IndexOf('.'); s = str.Substring(i, len - i); temp = "temp" + s; string key = count.ToString(); count++; CryptFile.EncryptFile <TripleDESCryptoServiceProvider>(@dialog.FileName, key, temp); File.Delete(dialog.FileName); File.Move(temp, str); ht.Add(str, key); } } else { errormessage(); } }
// открыть файл private void button2_Click(object sender, EventArgs e) { cam(); if (check()) { string key = ""; int i; OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog() == DialogResult.OK) { ICollection keys = ht.Keys; foreach (string sу in keys) { if (sу == dialog.FileName) { key += ht[sу]; } } if (key == "") { emprtyerror(); return; } string s, temp; string str = dialog.FileName; int len = str.Length; i = str.IndexOf('.'); s = str.Substring(i, len - i); temp = "temp" + s; CryptFile.DecryptFile <TripleDESCryptoServiceProvider>(dialog.FileName, key, temp); File.Delete(dialog.FileName); File.Move(temp, str); System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(str); System.Diagnostics.Process rfp = new System.Diagnostics.Process(); rfp = System.Diagnostics.Process.Start(psi); rfp.WaitForExit();//ожидание завершения процесса CryptFile.EncryptFile <TripleDESCryptoServiceProvider>(@str, key, temp); File.Delete(dialog.FileName); File.Move(temp, str); } else { errormessage(); } } }
private void EncryptButton_Click(object sender, EventArgs e) { if (OpenDialog.ShowDialog() == DialogResult.OK) { var textFileName = OpenDialog.FileName; var secureFile = new CryptFile(textFileName); secureFile.EncryptFile(); MessageBox.Show("File encrypted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } }