ID resolution
To sign an element of an XML document, the element must have an ID attribute that is unique in the document. If the XML uses a different name for the ID attribute, you need to define an ID resolution.
The ID resolution can be defined globally, if the ID attribute change applies to the whole XML, or locally, if it applies to a single element.
In the examples below, we sign the following XML, whose ID attribute is renamed to licenseId.
<license xmlns="http://www.lacunasoftware.com/">
<licenseInfo licenseId=":9e2e5bbc-b4a0-41dc-a342-98f1554f32a3">
<domain>www.contoso.com</domain>
<domain>www.contoso.com</domain>
<expiration>2016-03-23</expiration>
</licenseInfo>
</license>
Defining a global ID resolution table
If the change applies globally, the signing code is:
// Create ID resolution table for whole XML
var idResolutionTable = new XmlIdResolutionTable();
idResolutionTable.AddGlobalIdAttribute("licenseId");
var signer = new XmlElementSigner();
signer.SetXml(xml);
signer.SetSigningCertificate(cert);
signer.SetPolicy(policy);
signer.SetToSignElementId(":9e2e5bbc-b4a0-41dc-a342-98f1554f32a3");
signer.SetIdResolutionTable(idResolutionTable); // set ID resolution table
signer.ComputeSignature();
If the attribute has a specific namespace, you can pass it to the same method, @Lacuna.Pki.Xml.XmlIdResolutionTable.AddGlobalIdAttribute(System.String,System.String)
Defining a local ID resolution table
In this example, the ID change applies only to the <licenseInfo> element.
// Create ID resolution table for element name and namespace
var idResolutionTable = new XmlIdResolutionTable();
idResolutionTable.SetElementIdAttribute("licenseInfo", "http://www.lacunasoftware.com/", "licenseId");
var signer = new XmlElementSigner();
signer.SetXml(xml);
signer.SetSigningCertificate(cert);
signer.SetPolicy(policy);
signer.SetToSignElementId(":9e2e5bbc-b4a0-41dc-a342-98f1554f32a3");
signer.SetIdResolutionTable(idResolutionTable); // set ID resolution table
signer.ComputeSignature();
If the attribute has a specific namespace, you can pass it to the same method, @Lacuna.Pki.Xml.XmlIdResolutionTable.SetElementIdAttribute(System.String,System.String,System.String,System.String)
See also
- @Lacuna.Pki.Xml.XmlIdResolutionTable
- @Lacuna.Pki.Xml.XmlElementSigner