.NET不支持非标准XMLDSIG签名元素名称不支持、非标准、元素、名称

2023-09-04 06:10:47 作者:指尖花凉

我想实现一个行业的规范,需要有包膜的XML数字签名(XMLDSIG)。相反,符合例子(;签名> &LT )的我的规格使用自己的名称签名元素:

I'm trying to implement an industry spec that requires enveloped XML digital signatures (XMLDSIG). Instead of conforming to the examples (<Signature>) my spec uses its own name for the signature element:

<xs:element name="ensembleSignature" type="dsig:SignatureType" />
<!-- wish this was:  <xs:element ref="dsig:Signature" />  -->

所以元素没有被命名为签名,是该域的XML命名空间,而不是DSIG XML命名空间研究。

So the element isn't named 'Signature' and is in the domain's XML namespace instead of the dsig XML namespace.

通过大量额外的工作,我可以创建.NET这个自定义签名。

With a lot of extra work I can create this custom signature in .NET.

使用.NET SignedXml类创建&LT; D​​SIG:签字&GT;元素 我操作DOM删除&LT; D​​SIG:签字&GT;并重新创建元素为&lt; myns名字:ensembleSignature取代。

但似乎.NET无法验证传入&LT; myns名字:ensembleSignature&gt;中,即使我重新命名传入的元素回至&lt; DSIG:签字&GT;

But it seems .NET can't verify the incoming <myns:ensembleSignature>, even if I rename the incoming element back to <dsig:Signature>.

我一直在XMLDSIG规范了很多次,但他们所有的例子使用&lt;签名>它似乎并没有明确要求该元素的名称,即使是笼罩变换。因此,在SignedXml这是一个错误,它仅支持此单一元素的名称时,有在XMLDSIG规范没有这样的规定?

I've been over the XMLDSIG spec many times, and although all their examples use <Signature> it doesn't seem to specifically require this element name, even for enveloped transforms. So is this a bug in SignedXml that it only supports this single element name when there is no such requirement in XMLDSIG spec?

推荐答案

使用非标准的元素名称是不可能的.NET。但签名元素名称是不是消化的一部分,这样你就可以删除了自定义签名元素,并添加一个标准的签名元素名称(小于签名>),但要小心,不要更改任何空白或命名空间SignedInfo元素,因为SignedInfo中的是的摘要的一部分。在规范化方法我现在用的空白是显著,所以是元素的命名空间。

Using a non-standard element name isn't possible in .NET. But the signature element name isn't part of the digest, so you can remove the 'custom' signature element and add a 'standard' signature element name (<Signature>) but be careful not to change any whitespace or namespaces in the SignedInfo element, because SignedInfo IS part of the digest. In the canonicalization method I am using whitespace is significant, and so is the namespace of the elements.

在加载XML到XmlDocument的 找到&LT; customSignature的xmlns =htt​​p://b-to-b.com/Namespace> 创建新的元素&lt;签名> 将的和其中的所有儿童; customSignature>到 要小心,不要打扰&LT空白或命名空间范围内;。的SignedInfo> load XML into XmlDocument find <customSignature xmlns="http://b-to-b.com/Namespace"> create new element <Signature> move all children of <customSignature> to Be careful not to disturb whitespace or namespace context of <SignedInfo>.
 
精彩推荐
图片推荐