我有一个需要验证签名的 XML 文档。SignedInfo 元素具有指定算法“ http://www.w3.org/2001/10/xml-exc-c14n# ”的元素 CanonicalizationMethod 并且还有一个包含 PrefixList 属性的子元素 InclusiveNamespaces,如下所示:
<ds:SignedInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="soapenv"></ec:InclusiveNamespaces>
</ds:CanonicalizationMethod>...
我使用以下代码来创建我的 C14Transform 对象:
XmlDsigExcC14NTransform cn14Transform = new XmlDsigExcC14NTransform(false, "soapenv");
从哪里来"soapenv"
的PrefixList
属性。
当规范化上述 XML(忽略空格)时,它应该像这样出来(注意第xmlns:soapenv="..."
2 行的部分):
<ds:SignedInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="soapenv"></ec:InclusiveNamespaces>
</ds:CanonicalizationMethod>
...
我遇到的问题是xmlns:soapenv="..."
规范化时不包含该部分,导致签名验证失败。
我可以通过以编程方式插入它来解决这个问题,但这很痛苦,因为 PrefixList 内容会有所不同。