Hi,
Can Anyone tell me about checksum..? Or else please give me Any references link about checksum concept in c#..?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Mar 20, 2013, 10:30 AM
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);
}