Dim xmldoc As New DOMDocument50
Dim xmldsig As New MXDigitalSignature50
Dim dsigKey As IXMLDSigKey
Dim DSIGNS As String
Dim DispStr, file
Private Function LoadXML()
' Read the input xml file and display the content in the Text1.
DispStr = ""
If xmldoc.xml = "" Then
If file = "" Then
DispStr = "invalid input xml file name"
LoadXML = False
Exit Function
End If
End If
Path = App.Path + "\" + file
xmldoc.async = False
xmldoc.preserveWhiteSpace = True
xmldoc.validateOnParse = False
If xmldoc.Load(Path) = False Then
DispStr = DispStr + vbNewLine + _
"can't load " + Path + vbNewLine + xmldoc.parseError.reason
LoadXML = False
Exit Function
End If
xmldoc.setProperty "SelectionNamespaces", DSIGNS
DispStr = "Input signature element:" + vbNewLine + vbNewLine _
+ xmldoc.xml + vbNewLine
LoadXML = True
End Function
Private Function VerifyXML()
If xmldoc.xml = "" Then
DispStr = "signature doc is empty."
VerifyXML = False
Exit Function
End If
DispStr = DispStr + vbNewLine
Set signature = xmldoc.selectSingleNode(".//ds:Signature")
Set xmldsig.signature = signature
Set oKeyInfo = xmldoc.selectSingleNode(".//ds:KeyInfo/ds:KeyValue")
Set oPubKey = xmldsig.createKeyFromNode(oKeyInfo)
Set oVerifiedKey = xmldsig.verify(oPubKey)
If oVerifiedKey Is Nothing Then
DispStr = "verify failed." + vbNewLine
End If
DispStr = DispStr + "The signature has been verified.
" _
+ vbNewLine + vbNewLine
VerifyXML = True
End Function
Private Sub Form_Load()
' Resize the text box control to the size of the form
Text1.Top = 100
Text1.Left = 100
Text1.Width = Form1.Width - 350
Text1.Height = Form1.Height - 750
DSIGNS = "xmlns:ds='http://www.w3.org/2000/09/xmldsig#'"
file = "signature.dsa.xml"
If LoadXML = False Then
Text1.Text = DispStr
Exit Sub
End If
If VerifyXML = False Then
Text1.Text = DispStr
Exit Sub
End If
Text1.Text = DispStr
End Sub
Private Sub Form_Resize()
' Resize the text box control to the size of the form
Text1.Width = Form1.Width - 350
Text1.Height = Form1.Height - 750
End Sub
Try It!