Discuss this help topic in SecureBlackbox Forum

XML: Add reference to element in signature

To add the reference, which that points to the element inside the signature, you would need to:

  1. Create an unique id, which will be set for the referenced element
  2. Create a reference ( TElXMLReference ) and set its URI property based on the generated ID. This reference should be added after the call to TElXMLSigner.UpdateReferencesDigest() method, which performs reference computation, because we don't set URINode/URINodes/URIData/URIStream properties as there is nothing to reference at the moment. The component will automatically try to resolve and perform reference computation, when the signature is generated and saved to the XML document.
  3. After calling TElXMLSigner.GenerateSignature() or GenerateSignatureAsync() set an ID of the referenced element. See How To Change Attributes Of Signature Elements topic for details.

C#:


Signer.UpdateReferencesDigest();
...
// add the reference after UpdateReferencesDigest call, otherwise exception will be thrown
TElXMLReference Ref2 = new TElXMLReference();
Ref2.URI = "#KeyInfo1";
Signer.References.Add(Ref2);
...
Signer.GenerateSignature(); // or GenerateSignatureAsync() method, this method generates Signature structure that could be modified using Signer.Signature property
...
Signer.Signature.KeyInfo.ID = "KeyInfo1"; // set an Id for KeyInfo element
Delphi:

Signer.UpdateReferencesDigest();
...
// add the reference after UpdateReferencesDigest call, otherwise exception will be thrown
Ref2 := TElXMLReference.Create();
Ref2.URI := '#KeyInfo1';
Signer.References.Add(Ref2);
...
Signer.GenerateSignature(); // or GenerateSignatureAsync() method, this method generates Signature structure that could be modified using Signer.Signature property
...
Signer.Signature.KeyInfo.ID := 'KeyInfo1'; // set an Id for KeyInfo element

How To articles about XML signing (XMLDSig and XAdES)

Discuss this help topic in SecureBlackbox Forum