I'm using Michael Gallants DecodeCertKey example to get the public key
from an X509 certificate. I then create an RSAServiceProvider and try
to use it to CheckSignature() on the signed XML file. Other sources
such as http://www.infomosaic.net/XMLSign/SecureXMLVerifyWS.htm can
verify the signature, but .Net won't. Any ideas?
Here is the code I'm using:
' Verify the signature of an XML file and return the result.
Public Shared Function VerifyXmlFile(ByVal Name As String) As
Boolean
' 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.Load(Name)
Dim oRSA As RSACryptoServiceProvider
' Load the X509 certificate.
Dim x509Cert As X509Certificate =
X509Certificate.CreateFromCertFile("mycert.cer")
'//Create a new instance of RSACryptoServiceProvider.
oRSA = DecodeCertKey.DecodeObject(x509Cert.GetPublicKey() )
' Create a new SignedXml object and pass it
' the XML document class.
Dim signedXml As New SignedXml
' Find the "Signature" node and create a new
' XmlNodeList object.
Dim nodeList As XmlNodeList =
xmlDocument.GetElementsByTagName("ds:Signature")
' Load the signature node.
signedXml.LoadXml(CType(nodeList(0), XmlElement))
' Check the signature and return the result.
Return signedXml.CheckSignature(oRSA)
End Function