private void btn_Blowfish_Decrypt_Click(object sender, EventArgs e) { Stopwatch watch = new Stopwatch(); Stopwatch watch1 = new Stopwatch(); if (txt_Blowfish_Input.Text == "") { lblErrorMessage.Visible = true; lblErrorMessage.Text = "You must enter Input Value! "; } else if (txt_Blowfish_key.Text == "") { lblErrorMessage.Visible = true; lblErrorMessage.Text = "You must enter Key Value! "; } else if (txt_Blowfish_Input.TextLength < 16) { lblErrorMessage.Visible = true; lblErrorMessage.Text = "You must enter a value larger than 15 size! "; } else { string ciphertext = txt_Blowfish_Input.Text; // Get the key string key = txt_Blowfish_key.Text; var clearText_to_AES = Encoding.UTF8.GetBytes(txt_Blowfish_Input.Text); var key_to_AES = Encoding.UTF8.GetBytes(txt_Blowfish_key.Text); watch.Start(); BlowFish blowFish = new BlowFish(key); string plaintext = blowFish.Decrypt_CBC(ciphertext); watch.Stop(); lbl_Blowfish_time.Text = "Blowfish Time Decrypt = " + watch.Elapsed.TotalMilliseconds + " ms"; byte[] cipherText_to_AES = AesImplementation.Encrypt(clearText_to_AES, key_to_AES); watch1.Start(); byte[] plainText = AesImplementation.Decrypt(cipherText_to_AES, key_to_AES); watch1.Stop(); lbl_Blowfish_Aes_time.Text = "AES Time Decrypt = " + watch1.Elapsed.TotalMilliseconds + " ms"; if (watch.Elapsed.TotalMilliseconds < watch1.Elapsed.TotalMilliseconds) { lbl_Blowfish_Compare_time.Text = "Blowfish Decrypt is faster than AES Decrypt"; } else { lbl_Blowfish_Compare_time.Text = "AES Decrypt is faster than Blowfish Decrypt"; } txt_Blowfish_output.Text = plaintext; byte[] bytes = Encoding.UTF8.GetBytes(plaintext); txt_Blowfish_hex.Text = BitConverter.ToString(bytes); } }
private void btn_AES_Decrypt_Click(object sender, EventArgs e) { if (ValidateFields()) { try { Stopwatch watch = new Stopwatch(); Stopwatch watch1 = new Stopwatch(); lblErrorMessage.Visible = false; string plaintext_to_Blow = txt_AES_Input.Text; string key_to_Blow = txt_AES_key.Text; byte[] cipherText = Convert.FromBase64String(txt_AES_Input.Text); // Get the key var key = Encoding.UTF8.GetBytes(txt_AES_key.Text); // Decrypt the cipher text watch.Start(); byte[] plainText = AesImplementation.Decrypt(cipherText, key); watch.Stop(); lbl_AES_time.Text = "AES Decrypt = " + watch.Elapsed.TotalMilliseconds + " ms"; BlowFish blowFish = new BlowFish(key_to_Blow); string ciphertext_to_Blow = blowFish.Encrypt_CBC(plaintext_to_Blow); watch1.Start(); string plaintext_Blow = blowFish.Decrypt_CBC(ciphertext_to_Blow); watch1.Stop(); lbl_AES_Blowfish_time.Text = "Blowfish Decrypt = " + watch1.Elapsed.TotalMilliseconds + " ms"; if (watch.Elapsed.TotalMilliseconds < watch1.Elapsed.TotalMilliseconds) { lbl_AES_Compare_time.Text = "AES Decrypt is faster than Blowfish Decrypt"; } else { lbl_AES_Compare_time.Text = "Blowfish Decrypt is faster than AES Decrypt"; } lbl_AES_time.Visible = true; lbl_AES_Blowfish_time.Visible = true; lbl_AES_Compare_time.Visible = true; txt_AES_output.Text = Convert.ToBase64String(cipherText); // Set the right output txt_AES_output.Text = Encoding.UTF8.GetString(plainText); txt_AES_hex.Text = BitConverter.ToString(plainText); } catch (Exception exception) { MessageBox.Show($@"An error occured: {exception}"); } } }