Created
January 5, 2020 07:25
-
-
Save SumindaD/abead6e85d93b12897c8bb10cbfe8aa7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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