|
private
void
btnFile1_Click(object
sender,
EventArgs e)
{
if
(openFileDialog1.ShowDialog() ==
DialogResult.OK)
{
txtFile1.Text =
openFileDialog1.FileName;
}
}
private
void
btnFile2_Click(object
sender,
EventArgs e)
{
if
(openFileDialog1.ShowDialog() ==
DialogResult.OK)
{
txtFile2.Text =
openFileDialog1.FileName;
}
}
private
void
btnCompare_Click(object
sender,
EventArgs e)
{
if
((txtFile1.Text !=
"") &
(txtFile2.Text !=
""))
{
try
{
txtMd51.Text =
cMd5.GetMD5Hash(txtFile1.Text);
txtMd52.Text =
cMd5.GetMD5Hash(txtFile2.Text);
if
(txtMd51.Text == txtMd52.Text)
{
txtResult.Text =
"برابر";
txtResult.BackColor = System.Drawing.Color.FromArgb(102,255,204);
}
else
{
txtResult.Text =
"نابرابر";
txtResult.BackColor = System.Drawing.Color.FromArgb(255,
102, 153);
}
}
catch
{
MessageBox.Show("ورودی
نامعتبر",
"خطا
یک",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("ورودی
تهی",
"خطای
دو",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
public
static
string
GetMD5Hash(string
pathName) //
کد آقای تصدیقی
{
string strResult =
"";
string strHashData =
"";
byte[] arrbytHashValue;
System.IO.FileStream
oFileStream =
null;
System.Security.Cryptography.MD5CryptoServiceProvider
oMD5Hasher =
new
System.Security.Cryptography.MD5CryptoServiceProvider();
try
{
oFileStream =
GetFileStream(pathName);
arrbytHashValue =
oMD5Hasher.ComputeHash(oFileStream);
oFileStream.Close();
strHashData = System.BitConverter.ToString(arrbytHashValue);
strHashData =
strHashData.Replace("-",
"");
strResult = strHashData;
}
catch (System.Exception
ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message,
"Error!",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Error,
System.Windows.Forms.MessageBoxDefaultButton.Button1);
}
return (strResult);
}
|