private void btnCheckResult_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(tbPath.Text)) { WarningNotice.InputString(); return; } if (!File.Exists(tbPath.Text)) { WarningNotice.NotFound(); return; } FileInfo file = new FileInfo(tbPath.Text); Task.Factory.StartNew(() => { switch (gbSHAMode.Controls.OfType <RadioButton>().FirstOrDefault(rb => rb.Checked)) { case RadioButton rb1 when rb1.Name == rdbtnSHA1.Name: if (cbHMACMode.Checked) { ControlEnable(this.Controls, false); Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => HMACSHA1Encryption.Encrypt(file, tbHMACPassword.Text))); task.Wait(); this.Invoke(new Action(() => tbResult.Text = task.Result)); this.Invoke(new Action(() => WarningNotice.Completed())); ControlEnable(this.Controls, true); } else { ControlEnable(this.Controls, false); Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => SHA1Encryption.Encrypt(file))); task.Wait(); this.Invoke(new Action(() => tbResult.Text = task.Result)); this.Invoke(new Action(() => WarningNotice.Completed())); ControlEnable(this.Controls, true); } break; case RadioButton rb2 when rb2.Name == rdbtnSHA256.Name: if (cbHMACMode.Checked) { ControlEnable(this.Controls, false); Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => HMACSHA256Encryption.Encrypt(file, tbHMACPassword.Text))); task.Wait(); this.Invoke(new Action(() => tbResult.Text = task.Result)); this.Invoke(new Action(() => WarningNotice.Completed())); ControlEnable(this.Controls, true); } else { ControlEnable(this.Controls, false); Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => SHA256Encryption.Encrypt(file))); task.Wait(); this.Invoke(new Action(() => tbResult.Text = task.Result)); this.Invoke(new Action(() => WarningNotice.Completed())); ControlEnable(this.Controls, true); } break; case RadioButton rb3 when rb3.Name == rdbtnSHA384.Name: if (cbHMACMode.Checked) { ControlEnable(this.Controls, false); Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => HMACSHA384Encryption.Encrypt(file, tbHMACPassword.Text))); task.Wait(); this.Invoke(new Action(() => tbResult.Text = task.Result)); this.Invoke(new Action(() => WarningNotice.Completed())); ControlEnable(this.Controls, true); } else { ControlEnable(this.Controls, false); Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => SHA384Encryption.Encrypt(file))); task.Wait(); this.Invoke(new Action(() => tbResult.Text = task.Result)); this.Invoke(new Action(() => WarningNotice.Completed())); ControlEnable(this.Controls, true); } break; case RadioButton rb4 when rb4.Name == rdbtnSHA512.Name: if (cbHMACMode.Checked) { ControlEnable(this.Controls, false); Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => HMACSHA512Encryption.Encrypt(file, tbHMACPassword.Text))); task.Wait(); this.Invoke(new Action(() => tbResult.Text = task.Result)); this.Invoke(new Action(() => WarningNotice.Completed())); ControlEnable(this.Controls, true); } else { ControlEnable(this.Controls, false); Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => SHA512Encryption.Encrypt(file))); task.Wait(); this.Invoke(new Action(() => tbResult.Text = task.Result)); this.Invoke(new Action(() => WarningNotice.Completed())); ControlEnable(this.Controls, true); } break; } }); }
private void btnEncrypt_Click(object sender, EventArgs e) { switch (gbSHAMode.Controls.OfType <RadioButton>().FirstOrDefault(rb => rb.Checked)) { case RadioButton rb1 when rb1.Name == rdbtnSHA1.Name: tbToText.Text = (cbHMACMode.Checked) ? HMACSHA1Encryption.Encrypt(tbFromText.Text, tbHMACPassword.Text) : SHA1Encryption.Encrypt(tbFromText.Text); break; case RadioButton rb2 when rb2.Name == rdbtnSHA256.Name: tbToText.Text = (cbHMACMode.Checked) ? HMACSHA256Encryption.Encrypt(tbFromText.Text, tbHMACPassword.Text) : SHA256Encryption.Encrypt(tbFromText.Text); break; case RadioButton rb3 when rb3.Name == rdbtnSHA384.Name: tbToText.Text = (cbHMACMode.Checked) ? HMACSHA384Encryption.Encrypt(tbFromText.Text, tbHMACPassword.Text) : SHA384Encryption.Encrypt(tbFromText.Text); break; case RadioButton rb4 when rb4.Name == rdbtnSHA512.Name: tbToText.Text = (cbHMACMode.Checked) ? HMACSHA512Encryption.Encrypt(tbFromText.Text, tbHMACPassword.Text) : SHA512Encryption.Encrypt(tbFromText.Text); break; } }