Hi,
Can Anyone tell me about checksum..? Or else please give me Any references link about checksum concept in c#..?
CheckSum concept in C#
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Mar 20, 2013, 6:30 AM EDT
A check sum offers a way to do this.
Basically, you use an algorithm to compute a check sum for the data before you send it and then use the same algorithm to recompute the check sum after it has been received.
If the check sums match, then it's highly likely that no data corruption has taken place.
Conversely, if the check sums do not match, then the data has been corrupted.
There are many algorithms that can be used for this purpose. Ideally, you need an algorithm where even a small change in the data produces a significantly different check sum.
If the check sum is both small and of a fixed size, it can also be transmitted with the data itself rather than separately.
In C# it's common to use hashing algorithms such as MD5 or SHA1 to generate a hash code which can be used as a check sum. Both of these quickly generate a small hash code for a given stream of data - 16 bytes (MD5) and 20 bytes (SHA1).
For example to produce a check sum for a file, you would need code such as the following for MD5:
using System.IO;
using System.Security.Cryptography;
// ...
byte[] checkSum;
using (Stream fs = File.OpenRead("myfile.txt"))
{
checkSum = MD5.Create().ComputeHash(fs);
}