private void button1_Click(object sender, EventArgs e) { DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { string NameOfFile = openFileDialog1.FileName; string fileName = NameOfFile; FileInfo f = new FileInfo(fileName); long s1 = f.Length; if (s1 > 50000000) { MessageBox.Show("Selected file is too large ! : " + Convert.ToString(s1)); MessageBox.Show("Application is aborting! . . ."); Application.Exit(); } try { string[] file = NameOfFile.Split('\\'); MessageBox.Show(file[file.Length - 1]); byte[] FileRAW = File.ReadAllBytes(NameOfFile); string file_Encrypted = sy_C.encryptFile(FileRAW); string s_key = Convert.ToBase64String(sy_C.sessionkey); string iv = Convert.ToBase64String(sy_C.sessioniv); s_key = s_key.ToString(); iv = iv.ToString(); byte[] encrypted_sessionkey = Asy_e.EncryptData(s_key, File.ReadAllText("PublicKey.xml")); byte[] encrypted_iv = Asy_e.EncryptData(iv, File.ReadAllText("PublicKey.xml")); s_key = Convert.ToBase64String(encrypted_sessionkey); iv = Convert.ToBase64String(encrypted_iv); writer.WriteLine(file[file.Length - 1]); writer.WriteLine(s_key); writer.WriteLine(iv); writer.WriteLine(file_Encrypted); writer.Flush(); string message = reader.ReadLine(); MessageBox.Show(message); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
protected void EncryptCommand_Click(object sender, EventArgs e) { // Check for encryption key if (!File.Exists(KeyFileName)) { Response.Write("Missing encryption key. Please generate key!"); } try { byte[] data = AsymmetricEncryptionUtility.EncryptData( ClearDataText.Text, PublicKeyText.Text); EncryptedDataText.Text = Convert.ToBase64String(data); } catch { Response.Write("Unable to encrypt data!"); } }