Dim xmldoc As New DOMDocument50 Dim xmldsig As New MXDigitalSignature50 Dim dsigKey As IXMLDSigKey Dim dataObj As IXMLDOMNode Const DSIGNS = "xmlns:ds='http://www.w3.org/2000/09/xmldsig#'" Const INFILE = "signature.verify.dsa.xml" Private Function WriteLine(ByVal str As String) Text1.Text = Text1.Text + str + vbNewLine End Function Private Function writeClear() Text1.Text = "" End Function Private Function LoadXML(ByVal file As String) ' Read input xml file and display the content in the text1. Path = App.Path + "\" + file xmldoc.async = False xmldoc.preserveWhiteSpace = True xmldoc.validateOnParse = False xmldoc.resolveExternals = False If xmldoc.Load(Path) = False Then WriteLine "Can't load " + Path WriteLine "Reason: " + xmldoc.parseError.reason LoadXML = False Exit Function End If xmldoc.setProperty "SelectionNamespaces", DSIGNS Set xmldsig.signature = xmldoc.selectSingleNode(".//ds:Signature") LoadXML = True End Function Private Function VerifyXML() If xmldsig.signature Is Nothing Then WriteLine "Invalid signature." VerifyXML = False Exit Function End If Set oKeyInfo = xmldoc.selectSingleNode(".//ds:KeyInfo/ds:KeyValue") If oKeyInfo Is Nothing Then WriteLine "Invalid <KeyInfo> element." VerifyXML = False Exit Function End If Set oPubKey = xmldsig.createKeyFromNode(oKeyInfo) If oPubKey Is Nothing Then WriteLine "Can't generate public key for verification." VerifyXML = False Exit Function End If Set oVerifiedKey = xmldsig.verify(oPubKey) If oVerifiedKey Is Nothing Then WriteLine "Signature not verified." End If WriteLine "Signature verified." VerifyXML = True End Function Private Sub Form_Load() writeClear WriteLine "Verifyin signature." If LoadXML(INFILE) = True Then VerifyXML End If End Sub
Try It!