What is hash code ?
in simple language hash code is Unique code computed using Mathematical function which is used to Authenticate the data when transmitting over network.
Where Hash code is used ?
Hash code can be used for data authentication purpose for example if you are sending data on communication channel if some one reading the data in between can modify the data and send that modified data.
to prevent modification of data(ie Authenticate) Hash codes are used.
How receiver will know that intermediate person modified the data ?
when sender sends the data it computes the Hash code of the data/file he is transmitting.At receiver side when data arrive with hash code attached Receiver recomputes the hash code and compare it with attached Hash code.if both matches that means data is Intact no one modified the data.
You will argue here that what if intermediate person Modifies the data Recomputed the hash and attach it with modified data.for that reason Simply Computed hash code is not attached to the File,instead RSA Security algorithm is used to encrypt hash code and attach it with file.
so only Alleged receiver will be able to Retrieve Correct Attached hash code value and can compare to authenticate user.
Most popular hash code algorithms are MD5(Message Digest 5) and SHA1 (Secure hashing algorithm).
Here I will not mention how to Encrypt the hash code using RSA Cryptography algorithm.article just tells how to compute hash code.
If you want to learn how to Encrypt the data using RSA Algorithm you can refer this article
in simple language hash code is Unique code computed using Mathematical function which is used to Authenticate the data when transmitting over network.
Where Hash code is used ?
Hash code can be used for data authentication purpose for example if you are sending data on communication channel if some one reading the data in between can modify the data and send that modified data.
to prevent modification of data(ie Authenticate) Hash codes are used.
How receiver will know that intermediate person modified the data ?
when sender sends the data it computes the Hash code of the data/file he is transmitting.At receiver side when data arrive with hash code attached Receiver recomputes the hash code and compare it with attached Hash code.if both matches that means data is Intact no one modified the data.
You will argue here that what if intermediate person Modifies the data Recomputed the hash and attach it with modified data.for that reason Simply Computed hash code is not attached to the File,instead RSA Security algorithm is used to encrypt hash code and attach it with file.
so only Alleged receiver will be able to Retrieve Correct Attached hash code value and can compare to authenticate user.
Most popular hash code algorithms are MD5(Message Digest 5) and SHA1 (Secure hashing algorithm).
Here I will not mention how to Encrypt the hash code using RSA Cryptography algorithm.article just tells how to compute hash code.
If you want to learn how to Encrypt the data using RSA Algorithm you can refer this article
private void button1_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(txtFileName.Text))
{
FileStream fs = new FileStream(txtFileName.Text, FileMode.Open);
SHA1 hashFunction = SHA1.Create();
byte[] computedHashCode = hashFunction.ComputeHash(fs);
string HashInString = Convert.ToBase64String(computedHashCode);
lblHashCode.Text = HashInString;
fs.Close();
}
}
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string FileName = ofd.FileName;
txtFileName.Text = FileName;
}
}
![]() |
| Computing SHA1/MD5 Hash of the File using c# |





