Vote count:
0
This has been a problem for a few people I've seen but most have been about text enconding problems. This is a purely binary problem. Here is some sample code.
MD5 md5Bytes = MD5.Create(), md5Stream = MD5.Create();
var random = new Random();
var bytes = new byte[4096 * 2];
random.NextBytes(bytes);
var stream = new MemoryStream(bytes);
stream.Position = 0;
var bytesHash = md5Bytes.ComputeHash(bytes);
var streamHash = md5Stream.ComputeHash(stream);
for (int i = 0; i < bytesHash.Length; ++i)
if (bytes[i] != streamHash[i])
{
Console.WriteLine("Different content " + i);
break;
}
When I run this, to my surprise I get different results. Can somebody explain what's going on here shouldn't a MD5 of a byte array give the same results as a stream of identical content?
asked 37 secs ago
Aucun commentaire:
Enregistrer un commentaire