// Encrypt the file. private void encryptButton_Click(object sender, EventArgs e) { try { // Encrypt the file. string password = encryptPasswordTextBox.Text; string plainfile = plainfileTextBox.Text; string cipherfile = cipherfileTextBox.Text; CryptoExtensions.EncryptFile(password, plainfile, cipherfile); // Show the results. plaintextRtb.LoadFile(plainfile); // Make sure we don't try to show too many bytes. byte[] cipherbytes = File.ReadAllBytes(cipherfile); const int maxBytes = 1000; if (cipherbytes.Length > maxBytes) { byte[] bytes = new byte[maxBytes]; Array.Copy(cipherbytes, bytes, maxBytes); cipherbytes = bytes; } ciphertextTextBox.Text = cipherbytes.BytesToHex(); } catch (Exception ex) { string stars = new string('*', ex.Message.Length); ciphertextTextBox.Text = $"{stars}\n{ex.Message}\n{stars}"; } }
// Decrypt the file. private void decryptButton_Click(object sender, EventArgs e) { try { // Decrypt the file. string password = decryptPasswordTextBox.Text; string cipherfile = cipherfileTextBox.Text; string recoverfile = recoverfileTextBox.Text; CryptoExtensions.DecryptFile(password, cipherfile, recoverfile); // Show the results. recovertextRtb.LoadFile(recoverfile); } catch (Exception ex) { string stars = new string('*', ex.Message.Length); recovertextRtb.Text = $"{stars}\n{ex.Message}\n{stars}"; } }