MD5 or other checksum

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Gents,

I need the checksum of an xml file in order to verify that no changes has
been made to the file. How is this done.

Second, is it possible to 'embed' the MD5 checksum inside the very same
file. I guess not but perhaps if it is possible to make a partial checksum
not based on the first X characters of the file.

Thank you very
 
private void button16_Click(object sender, EventArgs e)
{
using ( FileStream fs =
System.IO.File.OpenRead(@"c:\windows\notepad.exe") )
{
MD5 m5 = MD5.Create();
byte[] hash = m5.ComputeHash(fs);
string base64Hash = Convert.ToBase64String(hash);
Console.WriteLine("Base64 MD5 hash of Notepad.exe: " + base64Hash);
}
}

You can do the same kind of thing with SHA1, SHA128, etc.
 
Jesper said:
I need the checksum of an xml file in order to verify that no changes has
been made to the file. How is this done.

Second, is it possible to 'embed' the MD5 checksum inside the very same
file. I guess not but perhaps if it is possible to make a partial checksum
not based on the first X characters of the file.

That wouldn't be particularly hard to do - open the file (as a stream),
read the first however-many bytes, then pass the stream to
MD5.ComputeHash.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top