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_Encrypt_Click(object sender, EventArgs e) { if (ValidateFields()) { try { Stopwatch watch = new Stopwatch(); Stopwatch watch1 = new Stopwatch(); lblErrorMessage.Visible = false; var clearText = Encoding.UTF8.GetBytes(txt_AES_Input.Text); string plaintext_to_Blow = txt_AES_Input.Text; string key_to_Blow = txt_AES_key.Text; // Get the key var key = Encoding.UTF8.GetBytes(txt_AES_key.Text); watch.Start(); byte[] cipherText = AesImplementation.Encrypt(clearText, key); watch.Stop(); lbl_AES_time.Text = "AES Time Encrypt = " + watch.Elapsed.TotalMilliseconds + " ms"; watch1.Start(); BlowFish blowFish = new BlowFish(key); string cipherText_to_Blow = blowFish.Encrypt_CBC(plaintext_to_Blow); watch1.Stop(); lbl_AES_Blowfish_time.Text = "Blowfish Time Encrypt = " + watch1.Elapsed.TotalMilliseconds + " ms"; if (watch.Elapsed.TotalMilliseconds < watch1.Elapsed.TotalMilliseconds) { lbl_AES_Compare_time.Text = "AES Encrypt is faster than Blowfish Encrypt"; } else { lbl_AES_Compare_time.Text = "Blowfish Encrypt is faster than AES Encrypt"; } lbl_AES_time.Visible = true; lbl_AES_Blowfish_time.Visible = true; lbl_AES_Compare_time.Visible = true; txt_AES_output.Text = Convert.ToBase64String(cipherText); txt_AES_hex.Text = BitConverter.ToString(cipherText); txt_AES_output.Enabled = true; } catch (Exception exception) { MessageBox.Show($@"An error occured: {exception}"); } } }