-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashbrown.cs
125 lines (117 loc) · 4.11 KB
/
Hashbrown.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace Hashbrown
{
public partial class Hashbrown : Form
{
public Hashbrown()
{
InitializeComponent();
}
private void browseBtn_Click(object sender, EventArgs e)
{
clearState();
OpenFileDialog openFileDialog1 = new OpenFileDialog
{
InitialDirectory = @"C:\",
Title = "Browse Files",
CheckFileExists = true,
CheckPathExists = true,
Filter = "All files (*) | *.*",
RestoreDirectory = true,
ReadOnlyChecked = true,
ShowReadOnly = true
};
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
fileNameTxt.Text = openFileDialog1.FileName;
}
}
private void verifyChecksumBtn_Click(object sender, EventArgs e)
{
clearState();
if (hashOutput.Text != string.Empty && hashInput.Text != string.Empty)
{
bool isEqual = hashOutput.Text.Equals(hashInput.Text.Trim(), StringComparison.InvariantCultureIgnoreCase);
if (isEqual)
{
outputTextBox.BackColor = Color.LightGreen;
outputTextBox.Text = "Verification Passed! The checksums match.";
}
else
{
outputTextBox.BackColor = Color.Red;
outputTextBox.Text = "Verification Failed! The checksums do not match.";
}
}
else
{
outputTextBox.BackColor = Color.LightYellow;
outputTextBox.Text = "Please provide a hash to compare to.";
}
}
private void hashTypeMD5RadioButton_CheckedChanged(object sender, EventArgs e)
{
clearState();
bool isEmpty = isFileNameEmpty();
if (hashTypeMD5RadioButton.Checked && !isEmpty)
{
hashOutput.Text = CalculateHash.CalculateMD5(fileNameTxt.Text);
verifyChecksumBtn.Enabled = true;
}
}
private void hashTypeSHA1RadioButton_CheckedChanged(object sender, EventArgs e)
{
clearState();
bool isEmpty = isFileNameEmpty();
if (hashTypeSHA1RadioButton.Checked && !isEmpty)
{
hashOutput.Text = CalculateHash.CalculateSHA1(fileNameTxt.Text);
verifyChecksumBtn.Enabled = true;
}
}
private void hashTypeSHA256RadioButton_CheckedChanged(object sender, EventArgs e)
{
clearState();
bool isEmpty = isFileNameEmpty();
if (hashTypeSHA256RadioButton.Checked && !isEmpty)
{
hashOutput.Text = CalculateHash.CalculateSHA256(fileNameTxt.Text);
verifyChecksumBtn.Enabled = true;
}
}
private void hashTypeCRC32RadioButton_CheckedChanged(object sender, EventArgs e)
{
clearState();
bool isEmpty = isFileNameEmpty();
if (hashTypeCRC32RadioButton.Checked && !isEmpty)
{
hashOutput.Text = CalculateHash.CalculateCRC32(fileNameTxt.Text);
verifyChecksumBtn.Enabled = true;
}
}
private void clearState()
{
outputTextBox.Text = string.Empty;
outputTextBox.BackColor = Color.Empty;
}
private bool isFileNameEmpty()
{
if (string.IsNullOrEmpty(fileNameTxt.Text))
{
outputTextBox.BackColor = Color.LightYellow;
outputTextBox.Text = "Please browse for a file before selecting the hash type.";
return true;
}
return false;
}
}
}