By looking here http://www.mobilefish.com/download/sepa_xml/pain.001.001.02.xml, it seems you were missing the xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
namespace from the Document node (probably because it was stripped by an XML parser). I have modified a little your code so that it use the using
syntax and I added the namespace if missing. Now it returns the right hash.
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = true;
doc.LoadXml(xml);
XmlNodeList list = doc.GetElementsByTagName("Document");
XmlElement node = (XmlElement)list[0];
node.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
string s = node.OuterXml;
// The XmlDsigC14NTransform will strip the UTF8 BOM
using (MemoryStream msIn = new MemoryStream(Encoding.UTF8.GetBytes(s)))
{
XmlDsigC14NTransform t = new XmlDsigC14NTransform(true);
t.LoadInput(msIn);
using (var hash = new SHA256Managed())
{
byte[] digest = t.GetDigestedOutput(hash);
string result = BitConverter.ToString(digest).Replace("-", String.Empty);
}
}