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:
' 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
(c) CREA 2002-2007 www.creasign.si