CreaSign

Create a Detached Signature

A detached signature is neither the enveloped nor the enveloping one. The data can be in a sibling document in the XML tree or it can be stored in an external file or other resource. To create a detached signature, follow these steps:

  1. Load the XML data that should be signed.
  2. Create a template <ds:Signature> node and place it at the desired location in the XML tree.
  3. Create a new XmlSignature object and attach it to the template node from the previous step.
  4. Create a new reference with an URI pointing to the node that you want to sign.
  5. Call the CreateSignature method.
' The following certificate will be used for signing
signingCert="CERT_FIND_SUBJECT_STR=CREA_TESTUSER_1"

' Load a sample xml from file
set doc=CreateObject("Msxml2.FreeThreadedDOMDocument.4.0")
doc.preserveWhiteSpace=true
doc.load "files\orders.xml" ' Create a template signature node set template = CreateObject("CreaSignClientIE.XmlSignature") ' Add the template to the desired place in the source document doc.documentElement.appendChild template.XmlNode

' Create the real signature object ' You must not use the template here because we have moved ' the underlying xml node by calling append child set cs = CreateObject("CreaSignClientIE.XmlSignature") set cs.XmlNode = template.XmlNode

' Now, append the reference which points only to the second order set r = cs.AddReference("","#second","") ' Create a signature cs.CreateSignature signingCert,0 ' Save the result to a file saveTo="files/signedDetached.xml" if WScript.Arguments.Count>0 then saveTo=WScript.Arguments(0) doc.save saveTo
WScript.Echo "Result saved to: " & saveTo


Send comments on this topic.

(c) CREA 2002-2007 www.creasign.si