c# - What is the difference between MD5 computeHash(Stream) and computeHash(byte[]) -
this has been problem few people i've seen have been text enconding problems. purely binary problem. here sample code.
md5 md5bytes = md5.create() ; md5 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); (int = 0; < byteshash.length; ++i) if ( bytes[i] != streamhash[i] ) { console.writeline("different content " + i); break; } when run this, surprise different results. can explain what's going on here shouldn't md5 of byte array give same results stream of identical content?
you're comparing data hash, of course it's not same; comparison should be:
if (byteshash[i] != streamhash[i]) and gives same results, expected ;)
Comments
Post a Comment