I am trying to implement a method for detecting duplicate files. I have an MD5 hashing method (let's ignore the fact that MD5 is broken) as below:
using(MD5 hasher = MD5.Create())
using(FileStream fs = File.OpenRead("SomeFile"))
{
byte[] hashBytes = hasher.ComputeHash(fs);
string hashString = string.Join(string.Empty, hashBytes.Select(x => x.ToString("X2")));
}
Instead of creating a string
out of the hashBytes
can I simply create a Guid
out of it like so?
Guid hashGuid = new Guid(hashBytes);
Would it still be valid or will I lose uniqueness?
MD5 hashes and Guid
essentially both express 128 bits of binary, so:
Guid
is a value-type means that you avoids an allocation compared to string
...Guid
multiple times)Guid
that won't really be respected/expected hereGuid
default formatting isn't the same as how MD5 hashes are usually expressedGuid
endianness is a mess, so if you want to get between raw bytes and any text representation: tread very carefully; it is not what you expectIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With