C # Signing XML Documents Using XAdES

I need to sign xml with an XAdES template. I use 2 links. The problem is the second, if I add Transform, it will work fine (signedXml.CheckSignature () returns True), without this conversion it will return False.

my code is:

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 the 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> 

Is this a problem in .NET?

Thanks.

+4
source share
1 answer

Otherwise, the node for XAdES is in the Signature node, after the node object you need to calculate the signature, and then add the node object and the required node after that, this can be easily done with programming, it depends on the level of wut XAdES that you are going to implement.

0
source

Source: https://habr.com/ru/post/1399334/


All Articles