I’ve been trying to serialize an object to xml and then hash the result but whenever I create the hash its always the same for different objects, not to sure what I’m doing wrong or have left out. Help would be appreciated.
Here is the code I’m using:
private static byte[] CreateHash<T>(T value)
{
using (MemoryStream stream = new MemoryStream())
using (SHA512Managed hash = new SHA512Managed())
{
XmlSerializer serialize = new XmlSerializer(typeof(T));
serialize.Serialize(stream, value);
return hash.ComputeHash(stream);
}
}
Rewind the stream:
After
Serialize, the stream is at the end, with no data available to be read.