get hash of a file

P

Pohihihi

I am trying to get HASH of contants of a file that I read.
I get byte[] from ComputeHash().
To get alpha-digits I put it into Guid to get Guid out of it.
Am I doing right?
When I create a new Guid is it alpha-digit representation of the contant it
is totally new value computed on byte[] and is not the real hash of file.

Any pointers will help me. Thx


System.IO.FileInfo fi = new System.IO.FileInfo(@"C:\h.html");
Stream fs = fi.Open(FileMode.Open,FileAccess.Read,FileShare.None);
HashAlgorithm hash = new MD5CryptoServiceProvider();
this.textBox1.Text = (new Guid(hash.ComputeHash(fs))).ToString() +
Environment.NewLine;
 
W

William Stacey [MVP]

Don't use a guid, just convert the byte[] to base64 or hex string to see it.
Why are you thinking guid here?
 
P

Pohihihi

Thanks, I guess I was not sure what is the correct output so I was trying
everything.

William Stacey said:
Don't use a guid, just convert the byte[] to base64 or hex string to see
it. Why are you thinking guid here?

--
William Stacey [MVP]

Pohihihi said:
I am trying to get HASH of contants of a file that I read.
I get byte[] from ComputeHash().
To get alpha-digits I put it into Guid to get Guid out of it.
Am I doing right?
When I create a new Guid is it alpha-digit representation of the contant
it is totally new value computed on byte[] and is not the real hash of
file.

Any pointers will help me. Thx


System.IO.FileInfo fi = new System.IO.FileInfo(@"C:\h.html");
Stream fs = fi.Open(FileMode.Open,FileAccess.Read,FileShare.None);
HashAlgorithm hash = new MD5CryptoServiceProvider();
this.textBox1.Text = (new Guid(hash.ComputeHash(fs))).ToString() +
Environment.NewLine;
 

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

Top