CreaSign

Create an Enveloped Signature

In an enveloped signature, the signed or to-be-signed data is an XML document and contains the <ds:Signature> element as its child element. To create an enveloped signature, follow these steps:

  1. Load the XML data that should be signed.
  2. Create a template <ds:Signature> node and place it at a 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 empty URI.
  5. Add the enveloping transform to the reference.
  6. 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 with an empty URI ' This will sign the whole document set r = cs.AddReference("","","") ' Finally, add the enveloped signature transform r.Transforms.Add "http://www.w3.org/2000/09/xmldsig#enveloped-signature" ' Create a signature cs.CreateSignature signingCert,0 ' Save the result to a file saveTo="files/signedEnveloped.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