Friday 15 March 2013

c# - Stream chaining in computing a checksum: avoiding memory issues -


I have a FileStream attached to an XML file which I would like to read directly in a SHA512 < / P>

This problem is two times:

  1. I want to leave some of the nodes in Xml
  2. The file is quite large, and the whole thing Can not load in memory

    I can read the entire file in an XML structure, delete the node, then type it into the stream that SHA512.ComputeHash < Plugged in / code> It will be a performance loss, but I like to be able to remove the nodes as an operation in some currents and then somehow combines the streams together in one stream which SHA512 ComputeHash (stream) can be passed in .

    How can I complete this?

     using  (var hash = (Var reader = XmlReader.creative ("input. Xml ") using the new SHA512Cng ()) using (var author = XmlWriter.Create (stream)) (var stream = new cryptostream (stream.null, hash, cryptostream mode.)) {While ( Reader.Read ()) {// ... write author node ...} author.flush (); stream.FlushFinalBlock (); var result = hash.hash;}    

No comments:

Post a Comment