Skip to content

Instantly share code, notes, and snippets.

@SumindaD
Created January 5, 2020 07:25
Show Gist options
  • Save SumindaD/abead6e85d93b12897c8bb10cbfe8aa7 to your computer and use it in GitHub Desktop.
Save SumindaD/abead6e85d93b12897c8bb10cbfe8aa7 to your computer and use it in GitHub Desktop.
/// <summary>
/// Verify the integrity of the signed XML document
/// </summary>
/// <param name="xmlFilePath">Path to the signed xml document</param>
/// <param name="certificate">X509Certificate2 Public key certificate</param>
/// <returns></returns>
private static bool VerifyXMLDocument(string xmlFilePath, X509Certificate2 certificate)
{
var xmlDocument = ReadXMLDocumentFromPath(xmlFilePath);
var signedXml = new SignedXml(xmlDocument);
// Load the XML Signature
var nodeList = xmlDocument.GetElementsByTagName("Signature");
signedXml.LoadXml((XmlElement)nodeList[0]);
// Verify the integrity of the xml document
using (var rsaKey = certificate.PublicKey.Key)
{
return signedXml.CheckSignature(rsaKey);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment