/// <summary> /// Calculates the Hash value based on the selected algorithm and file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCalculateHash_Click(object sender, EventArgs e) { //Get the hash algorithm selected by the user // if nothing selected show a message to select one // Same for file to calculate the hash of if (cbHashAlgorithms.Text == "--Select--") { MessageBox.Show("Select a hash algorithm"); } else if (String.IsNullOrEmpty(FILE_TO_EVAL)) { MessageBox.Show("Select a file to verify"); } else { //Everything is validated, so lets create an object of the Calculator Class ClassLibraries.calculator objCalculator = new ClassLibraries.calculator(); string[] returnedCalculation = objCalculator.CalculateHash(FILE_TO_EVAL, cbHashAlgorithms.Text.ToString()); if (string.Equals(returnedCalculation[0], "success")) { txtSimpleHashValue.Text = returnedCalculation[1]; //Enable the "Save to file" button btnSaveHashToFile.Enabled = true; } else //This block executes when their is an error { MessageBox.Show(returnedCalculation[0]); } } }
/// <summary> /// Start the hash calculation process. Triggers when the user clicks on /// "Validate the file" button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCalculateHash_Click(object sender, EventArgs e) { //Get the hash algorithm selected by the user // if nothing selected show a message to select one // Same for file to calculate the hash of if (cbHashAlgorithms.Text == "--Select--") { MessageBox.Show("Select a hash algorithm"); } else if (String.IsNullOrEmpty(FILE_TO_EVAL)) { MessageBox.Show("Select a file to verify"); } else if (String.IsNullOrEmpty(txtHashValue.Text)) { MessageBox.Show("Provide a pre-calculated hash to verify against"); } else { //Everything is validated, so lets create an object of the Calculator Class ClassLibraries.calculator objCalculator = new ClassLibraries.calculator(); string[] returnedCalculation = objCalculator.CalculateHash(FILE_TO_EVAL, cbHashAlgorithms.Text.ToString()); if (string.Equals(returnedCalculation[0], "success")) { //if (String.IsNullOrEmpty(txtHashValue.Text)) //{ // txtResults.Text = returnedCalculation[1]; //} //else if (String.Equals(returnedCalculation[1], txtHashValue.Text)) if (String.Equals(returnedCalculation[1], txtHashValue.Text)) { txtResults.BackColor = System.Drawing.Color.Green; txtResults.Text = "Valid File!!!"; } else { txtResults.BackColor = System.Drawing.Color.Red; txtResults.Text = "Invalid File!!"; } } else //This block executes when their is an error { MessageBox.Show(returnedCalculation[1]); } } }
/// <summary> /// Start the hash calculation process. Triggers when the user clicks on /// "Validate the file" button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCalculateHash_Click(object sender, EventArgs e) { //Get the hash algorithm selected by the user // if nothing selected show a message to select one // Same for file to calculate the hash of if (cbHashAlgorithms.Text == "--Select--") { MessageBox.Show("Select a hash algorithm"); } else if (String.IsNullOrEmpty(FILE_TO_EVAL)) { MessageBox.Show("Select a file to verify"); } else if (String.IsNullOrEmpty(txtHashValue.Text)) { MessageBox.Show("Provide a pre-calculated hash to verify against"); } else { //Everything is validated, so lets create an object of the Calculator Class ClassLibraries.calculator objCalculator = new ClassLibraries.calculator(); string[] returnedCalculation = objCalculator.CalculateHash(FILE_TO_EVAL, cbHashAlgorithms.Text.ToString()); if (string.Equals(returnedCalculation[0], "success")) { //if (String.IsNullOrEmpty(txtHashValue.Text)) //{ // txtResults.Text = returnedCalculation[1]; //} //else if (String.Equals(returnedCalculation[1], txtHashValue.Text)) if (String.Equals(returnedCalculation[1], txtHashValue.Text)) { txtResults.BackColor = System.Drawing.Color.Green; txtResults.Text = "Valid File!!!"; } else { txtResults.BackColor = System.Drawing.Color.Red; txtResults.Text = "Invalid File!!"; } } else //This block executes when their is an error { MessageBox.Show(returnedCalculation[1]); } } }