private void EncryptClick(object sender, RoutedEventArgs e) { string text = new TextRange(rtb_encrypt.Document.ContentStart, rtb_encrypt.Document.ContentEnd).Text; string key = new Crypta().RandomKey(); string cipher = new Crypta().AESEncryption(text, key); tb_enckey.Text = key; rtb_encrypt.Document.Blocks.Clear(); rtb_encrypt.Document.Blocks.Add(new Paragraph(new Run(cipher))); }
private void DecryptClick(object sender, RoutedEventArgs e) { try { string text = new TextRange(rtb_decrypt.Document.ContentStart, rtb_decrypt.Document.ContentEnd).Text; string key = tb_dekey.Text; string decrypted_text = new Crypta().AESDecryption(text, key); rtb_decrypt.Document.Blocks.Clear(); rtb_decrypt.Document.Blocks.Add(new Paragraph(new Run(decrypted_text))); } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR!", MessageBoxButton.OK, MessageBoxImage.Error); } }