G
Guest
How can I add an MD5 hash to XMLSerializer.Serialize without corrupting the
content of the file; then how to read it back to verify is correct?
I'd like to code up something (see below) that looks like this, but I'm not
sure this is correct approach to the problem. Once I add the signature, the
file won't test the same way again. I know I could add it to the bottom of
the file, but then everyone would have to know my algorithm for correct
computation, it seems to me there should be a standard way to do this.
Example (ignore coding errors, I'm after the logic)
XmlSerializer xs = new XmlSerializer(class types);
FileStream fs = new FileStream(Create, Write, None);
xs.Serialize (fs, class types)
AddMD5(fs); <-- How to implement?
function AddMD5( FileStream )
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
using (FileStream fs = new FileStream( fs )
hash = md5.ComputeHash(fs);
-->> Add hash to filestream
}
function VerifyMD5 (FilesStream )
{
// nothing will match, without custom algorithm
}
Any help would be appreciated.
Jim
I'm not even sure this is the correct approach to this problem;
content of the file; then how to read it back to verify is correct?
I'd like to code up something (see below) that looks like this, but I'm not
sure this is correct approach to the problem. Once I add the signature, the
file won't test the same way again. I know I could add it to the bottom of
the file, but then everyone would have to know my algorithm for correct
computation, it seems to me there should be a standard way to do this.
Example (ignore coding errors, I'm after the logic)
XmlSerializer xs = new XmlSerializer(class types);
FileStream fs = new FileStream(Create, Write, None);
xs.Serialize (fs, class types)
AddMD5(fs); <-- How to implement?
function AddMD5( FileStream )
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
using (FileStream fs = new FileStream( fs )
hash = md5.ComputeHash(fs);
-->> Add hash to filestream
}
function VerifyMD5 (FilesStream )
{
// nothing will match, without custom algorithm
}
Any help would be appreciated.
Jim
I'm not even sure this is the correct approach to this problem;