问题描述
我需要签署的XAdES模板XML。我使用2引用。问题是与第二,如果加变换我,它会正常工作(signedXml.CheckSignature()返回True),没有这个改造,将返回False。
I need to sign xml with XAdES template. I am using 2 references. The problem is with second, if I add Transform, it will work fine (signedXml.CheckSignature() return True), without this transform it will return False.
我的代码
System.Security.Cryptography.Xml.Reference reference2;
System.Security.Cryptography.Xml.SignedXml signedXml;
...
reference2 = new Reference();
reference2.Type = "http://uri.etsi.org/01903/v1.1.1#SignedProperties";
reference2.Uri = "#SignedPropertiesId";
//reference2.AddTransform(new XmlDsigExcC14NTransform()); IF I COMMENT THIS LINE IT WONT WORK
signedXml.AddReference(reference2);
signedXml.ComputeSignature();
XmlElement xmlDigitalSignature = signedXml.GetXml();
xmlDoc.DocumentElement.AppendChild(xmlDoc.ImportNode(xmlDigitalSignature, true));
signedXml.CheckSignature(); //return false if dont use Transform in second REF
signedXml.ComputeSignature();
XmlElement xmlDigitalSignature = signedXml.GetXml();
xmlDoc.DocumentElement.AppendChild(xmlDoc.ImportNode(xmlDigitalSignature, true));
签名的第二部分。
second part of signature.
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>cert...</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
<ds:Object>
<xds:QualifyingProperties Target="#SignatureId">
<xds:SignedProperties Id="SignedPropertiesId">
<xds:SignedSignatureProperties>
在.NET中这个问题?
is that problem in .NET ?
感谢。
推荐答案
您就错了的XAdES节点是在签名节点,目标节点之后,您需要计算签名通常然后添加对象节点事后必要的节点,这可以很容易地通过编程完成这取决于你要实现的XAdES的WUT水平。
Your doing it wrong the node for XAdES is in the Signature node, after the object node, you need to compute signature normally then add the object node and the necessary node afterwards, this can be done easily through programing it depends on wut level of XAdES you are going to implement.
这篇关于用的XAdES C#签名XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!