CreaSign

Sign a File

When data-to-be-signed is not a part of the XML document, a resolver class is used to resolve references to the data. For example, you can use FileSystemResolver to sign the data that is stored in an external file. To sign a file, follow these steps:

  1. Create a new XmlSignature object.
  2. Create a resolver and attach it to the XmlSignature object.
  3. Add reference to the desired data.
  4. Call the CreateSignature method.

The following example uses FileSystemResolver to sign a file:

' The following certificate will be used for signing
signingCert="CERT_FIND_SUBJECT_STR=CREA_TESTUSER_1"

' Create an xml signature object
Set cs = CreateObject("CreaSignClientIE.XmlSignature")

' Create a file system resolver and initialize it
Set r = CreateObject("CreaSignClientIE.FileSystemResolver")
rootPath = Mid(WScript.ScriptFullName,1,InStrRev(WScript.ScriptFullName,"\"))
r.RootPath = rootPath

' Attach the resolver to the xml signature object Set cs.Resolver = r

' Add a reference to the file we want to sign
cs.AddReference "","files\someFile1.txt","" ' Create a signature cs.CreateSignature signingCert,0 ' Save the result to a file saveTo="files/signedFile.xml" if WScript.Arguments.Count>0 then saveTo=WScript.Arguments(0) cs.XmlNode.ownerDocument.save saveTo

WScript.Echo "Result saved to: " & saveTo


Send comments on this topic.

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