|
Visual Basic Script / ASP Development
Visual Basic 6.0 Development
The process of using SecureXML from VBScript
either on the client side or on an ASP page on the server side starts
with first creating an instance of the SecureXML Signature object
by doing a CreateObject on the object name:
Set SigObj = CreateObject("XMLSign.Signature") on the
client side and
Set SigObj = Server.CreateObject("XMLSign.Signature")
on an ASP page for server side usage.
Access to all methods and properties are straight forward as their
names remain exactly the same as in the XMLSign.idl file.
Example 1: PKI Signature, Co-Signing
'Create SecureXML Signature object
Set SigObj = CreateObject("XMLSign.Signature")
'Set a signature property
SigObj.ChangeOrAddProperty "Signer Name", "John Doe"
' Set ExcludeSignerCertificate to 1 if you don't want to include
a copy of the signer's certificate in the signed XML
SigObj.ExcludeSignerCertificate = 1
' Just sign a simple data string
res = SigObj.SignDataStr("This is my test data")
'Co-sign the signed xml produced above
res = SigObj.CoSignXMLStr(res)
'Check for errors
MsgBox(SigObj.GetLastError)
'Save the signed xml containing two signatures to a file
SigObj.SaveXMLStr res, "TestFiles\c1.xml"
'Verify the signed XML created above
res = SigObj.SecureXMLVerify(res)
'Display verification result
MsgBox(res)
Example 2: HMAC or Password based signatures
'Create SecureXML Signature object
Set SigObj = CreateObject("XMLSign.Signature")
'Set Signature Id
SigObj.SignatureID(0) = "MySignature"
' Set EnvelopingFlag to Enveloped mode
SigObj.EnvelopingFlag = 2
' Enable HMAC signing
SigObj.UseHMAC = 1
' Set the signing password
SigObj.HMACPassword = "password"
'Set some other signature property
SigObj.ChangeOrAddProperty "Location", "Honolulu"
'Create the signature
res1 = SigObj.Sign("TestFiles\catalog.xml")
MsgBox res1 & "Last Error = " & SigObj.GetLastError
'Enable SaveXMLSignature to overwrite existing files
SigObj.OverwriteFile = 1
'Save the signature created above
SigObj.SaveXMLSignature "TestFiles\c1.xml"
MsgBox "Signature Saved As TestFiles\c1.xml"
Visual Basic Script / ASP Development
Visual Basic 6.0 Development
There are two ways to create an instance
of the SecureXML Digital Signature object in Visual Basic 6.0. One
way is to follow the usage presented for Visual Basic Script. This
method, also know as late binding method has a disadvantage that
you don't get the benefit of the Intellisense built into the VB
6.0 development environment. Also there is a run-time penalty for
late binding. The preferred way is to create a reference to the
SecureXML Digital Signature type library in your VB 6.0 development
environment and then declare a typed object. In order to create
a reference to the SecureXML Digital Signature Type Library, please
click on Project pull down menu and select References
At this
point you will be presented with a dialog box with a list of available
references. Please locate and select an entry called "Infomosaic
SecureXML Digital Signature 1.0 Type Library". If you don't
find this entry, click on the browse button and locate and select
XMLSign.dll in C:\Program Files\Infomosaic\SecureXML\ directory
or the SecureXML install directory if you chose a different directory
during installation.
After you have created a reference to the SecureXML Digital Signature
Type Library you would need to declare a variable of this new type.
This is done as follows:
Public SigObj As XMLSIGNLib.Signature
Later in your code, you would need to create an instance of the
SecureXML object as follows:
Set SigObj = New XMLSIGNLib.Signature
Now SigObj points to an instance of the SecureXML Digital Signature
object and the VB 6.0 development environment can help you use it
by presenting you with a list of methods and properties available
for this object. For the most part if you go through the sample
VB 6.0 project included with the SecureXML download, you will have
your first VB application running within one or two days.
With VB, all the method and property names remain the same as in
the IDL file and the VB 6.0 Intellisense can help you use them without
having to read this guide in great detail.
|