【发布时间】:2016-05-27 15:31:13
【问题描述】:
Private Sub VerifyButton_Click(sender As Object, e As EventArgs) Handles VerifyButton.Click
' Create a new XML document.
'
Dim xmlDocument As New XmlDocument
' Format using white spaces.
'
xmlDocument.PreserveWhitespace = True
' Load the passed XML file into the document.
'
xmlDocument.LoadXml(ToVerifyTextBox.Text)
' Create a new SignedXml object and pass it the XML document class.
'
Dim signedXml As New SignedXml(xmlDocument)
' Find the “Signature” node and create a new XmlNodeList object.
'
Dim nodeList As XmlNodeList = xmlDocument.GetElementsByTagName("Signature", "http://www.w3.org/2000/09/xmldsig#")
If nodeList.Count <= 0 Then
MessageBox.Show("Verification failed: No Signature was found in the document.")
' This example only supports one signature for
' the entire XML document. Throw an exception
' if more than one signature was found.
ElseIf nodeList.Count >= 2 Then
MessageBox.Show("Verification failed: More that one signature was found for the document.")
Else
' Load the signature node.
'
signedXml.LoadXml(CType(nodeList(0), XmlElement))
' Check the signature and show the result.
'
If signedXml.CheckSignature() Then
MessageBox.Show("Signature verified!")
Else
MessageBox.Show("Invalid signature!!!")
End If
End If
End Sub
此代码将通过 xml 文件并找到标记签名和验证为有效的签名,但我想检查并将密钥与 xml 文件中的密钥进行比较,如果可以,则签名验证为有效.
【问题讨论】:
标签: xml vb.net x509certificate2