Discuss this help topic in SecureBlackbox Forum

XML: Load signature

To load the signature from an XML document you need to select a ds:Signature element using XML DOM methods or using XPath expression, then you need to create an instance of TElXMLVerifier class, then call TElXMLVerifier.Load() method.

Additionally, if your signature contains XAdES information, you need to create an instance of TElXAdESVerifier class and assign it to TElXMLVerifier.XAdESProcessor property in order to load XAdES information too.

If the XML document is supposed to contain only one signature, you can pass a document element to TElXMLVerifier.Load() method. In this case the component will automatically search for the first occurrence of the ds:Signature element.

The sample code below uses XPath expression to select all signature nodes and then load them:

C#:


TElXMLNamespaceMap NSMap = new TElXMLNamespaceMap();

NSMap.AddNamespace("ds", SBXMLDefs.xmlSignatureNamespace);
NodeSet = XMLDocument.SelectNodes("//ds:Signature", NSMap);

for (int i = 0; i < NodeSet.Count; i++)
{
  TElXMLVerifier Verifier = new TElXMLVerifier(null);
  TElXAdESVerifier XAdESVerifier = new TElXAdESVerifier(null);

  Verifier.XAdESProcessor = XAdESVerifier;
  Verifier.Load(NodeSet.get_Node(i) as TElXMLDOMElement);
  //... verify signature here ...
}
Delphi:

NSMap := TElXMLNamespaceMap.Create;
try
  NSMap.AddNamespace('ds', SBXMLDefs.xmlSignatureNamespace);
  NodeSet := XMLDocument.SelectNodes('//ds:Signature', NSMap);
  try
    for i := 0 to NodeSet.Count - 1 do
    begin
      Verifier := TElXMLVerifier.Create(nil);
      XAdESVerifier := TElXAdESVerifier.Create(nil);
      try
        Verifier.XAdESProcessor := XAdESVerifier;
        Verifier.Load(NodeSet[i] as TElXMLDOMElement);
        // verify signature
      finally
        FreeAndNil(Verifier);
        FreeAndNil(XAdESVerifier);
      end;
    end;
  finally
    FreeAndNil(NodeSet);
  end;
finally
  FreeAndNil(NSMap);
end;

How To articles about XML signing (XMLDSig and XAdES)

Discuss this help topic in SecureBlackbox Forum