public bool Verify() { var signatureXml = GetSignature(); var signedXml = new ExtendedSignedXml(Xml); signedXml.LoadXml(signatureXml); foreach (var attachment in Attachments) { var reference = new Reference(attachment.Stream) { Uri = "cid:" + attachment.ContentId, DigestMethod = SignedXml.XmlDsigSHA256Url }; reference.AddTransform(new AttachmentContentSignatureTransform()); signedXml.AddExternalReference(reference); } var securityXml = GetSecurity(); var security = XmlToObject.Deserialize <AS4.Security.Security>(securityXml); var certificate = new X509Certificate2(security.BinarySecurityToken.Value); return(signedXml.CheckSignature(certificate.GetRSAPublicKey())); }
public bool Verify() { var signedXml = new ExtendedSignedXml(Xml); var signature = GetSignature(Xml); signedXml.LoadXml(signature); return(signedXml.CheckSignature()); }
private static VerificationResults PerformValidationFromXml(string xml, VerificationParameters validationParameters) { var document = new XmlDocument { PreserveWhitespace = true }; document.LoadXml(xml); var newsignedXml = new ExtendedSignedXml(document); if (document.DocumentElement == null) { throw new InvalidDocumentException("Document has no root element"); } var signatureNode = XmlDsigNodesHelper.GetSignatureNode(document); newsignedXml.LoadXml(signatureNode); var verificationCertificate = GetVerificationCertificate(newsignedXml, validationParameters); if (verificationCertificate == null) { throw new Exception("Signer public key could not be found"); } if (!newsignedXml.CheckSignature(verificationCertificate, !validationParameters.VerifyCertificate)) { throw new InvalidOperationException("Signature is invalid."); } var results = new VerificationResults { Timestamp = GetTimeStampFromSignature(document), OriginalDocument = GetDocumentFromSignature(document), SigningCertificate = GetCertificateFromSignature(document) }; return(results); }