如果我想用封装签名签署下一个 XML 代码:
<root>
<element>
<child>text node</child>
</element>
</root>
然后签名 XML 代码发生在签名的 XML 代码中,如下所示:
<root>
<element>
<child>text node</child>
</element><Signature xmlns="http://www.w3.org/2000/09/xmldsig#">...</Signature>
</root>
Notice: no line break nor single character is added outside Signature element since that would invalidate the signature.
XML 封装的签名代码包括一个 ,它指定代码必须经受的修改,严格来说,无论是在签名还是验证过程中都完成了。 是下一个:
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
在 W3C 网站(官方文档)中,上面的表达式与下面的表达式进行了比较。在这两种情况下,必须产生相同的输出。
<XPath xmlns:dsig="&dsig;">
count(ancestor-or-self::dsig:Signature |
here()/ancestor::dsig:Signature[1]) >
count(ancestor-or-self::dsig:Signature)</XPath>
引用:http://www.w3.org/TR/xmldsig-core/#sec-EnvelopedSignature
变换前:
案例1(签字):
<root>
<element>
<child>text node</child>
</element>
</root>
案例2(签名):
<root>
<element>
<child>text node</child>
</element><Signature xmlns="http://www.w3.org/2000/09/xmldsig#">...</Signature>
</root>
变换后:
<root>
<element>
<child>text node</child>
</element>
</root>
在这两种情况下,都会产生相同的输出,这使我们能够验证签名数据的真实性。
我仍然遇到服务器说我的签名无效的问题,有人可以确认我是否正确地进行了转换吗?
非常感谢
问候
最佳答案
Transform 所做的就是擦除整个 Signature 元素及其后代。一个实际的例子是下一个签名数据:
<root>
<element>
<child>text node</child>
</element>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">...</Signature>
</root>
Transform 必须产生下一个输出:
<root>
<element>
<child>text node</child>
</element>
</root>
请注意,签名之外的每个字符都被保留,包括每个换行符和空格键。如果我们用冒号表示空格,我们有下一个 View :
<root>
::<element>
::::<child>text node</child>
::</element>
::
</root>
我建议访问下一个链接,从那里我能够清除我对这个问题的所有疑虑:
http://www.di-mgt.com.au/xmldsig2.html
最好的链接是它包含一个真实的签名示例,任何人都可以从中复制相同的 DigestValue 并确认文档(实践部分在学习过程中非常重要)。
关于xml - 封装的签名究竟会转换什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24961073/