My requirement is to verify the signature of the SOAP response.
This is my code:
public bool VerifyXmlSignatureAsync(string xml)
{
var xmlDoc = new XmlDocument() { PreserveWhitespace = true};
xmlDoc.LoadXml(xml);
XmlNode binarySecurityTokenNode = xmlDoc.SelectSingleNode("//wsse:BinarySecurityToken", GetNamespaceManager(xmlDoc));
if (binarySecurityTokenNode == null)
return false;
byte[] certBytes = Convert.FromBase64String(binarySecurityTokenNode.InnerText);
X509Certificate2 serverCert = new(certBytes);
var signatureNode = xmlDoc.GetElementsByTagName("Signature");
SignedXmlWithId signedXml = new(xmlDoc);
signedXml.LoadXml((XmlElement?)signatureNode[0]);
return signedXml.CheckSignature(serverCert, true);
}
CheckSignature method returns false. I have tried various other ways but nothing seems to work.