文档的摘要值为HP855e32qDMu4fzAZr+wXRqfeLh9HTpnAlAFy/jDg= 当我尝试使用下面的代码检查它时,结果是Ppk6zE8XY4zaIPco/fY/sSKog3imkmko8CMAIHVNwTw= 我认为问题出在包含空格的 Body 标记中。如果在没有空格的情况下签署此文档,则摘要值相等。
谁能看出错误?
public static byte[] GetDigest(XmlDocument doc)
{
var nodeList = doc.GetElementsByTagName(
"Signature", "http://www.w3.org/2000/09/xmldsig#");
var signedXml = new SignedXml(doc);
signedXml.LoadXml((XmlElement)nodeList[0]);
var signatureDescription = CryptoConfig.CreateFromName(signedXml.SignedInfo.SignatureMethod) as SignatureDescription;
var hashAlgorithm = signatureDescription.CreateDigest();
var xmlDocument = new XmlDocument
{
PreserveWhitespace = true
};
var body = doc.SelectSingleNode("/ReportEnvelope/Body");
XmlNodeList transformNode = ((XmlElement)(nodeList[0])).GetElementsByTagName("Transform");
xmlDocument.AppendChild(xmlDocument.ImportNode(body, true));
var transform = signedXml.SignedInfo.CanonicalizationMethodObject;
transform.LoadInnerXml(transformNode);
transform.LoadInput(xmlDocument);
return transform.GetDigestedOutput(hashAlgorithm);
}