我对 XmlDsigC14NTransform 有疑问。我试图重复来自 http://www.di-mgt.com.au/xmldsig2.html的示例(部分组成规范化的 SignedInfo 元素并计算其 SignatureValue),但我的代码从 xml 中丢失了空格,我无法获得正确的 hexdump。
我的 C# 代码:
XmlDocument signedInfoXml = new XmlDocument();
signedInfoXml.Load(@"C:\temp\new_sign.txt");
XmlDsigC14NTransform xmlTransform = new XmlDsigC14NTransform();
xmlTransform.LoadInput(signedInfoXml);
MemoryStream memoryStream = (MemoryStream)xmlTransform.GetOutput();
return BitConverter.ToString(memoryStream.ToArray()).Replace("-"," ");
源 Xml(来自文件 C:\temp\new_sign.txt):
<SignedInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue>UWuYTYug10J1k5hKfonxthgrAR8=</DigestValue>
</Reference>
</SignedInfo>
我如何将空格保存到我的 xml 中并像示例(http://www.di-mgt.com.au/xmldsig2.html)中那样获得规范化的 xml?