public XDocument Sign() { using (var key = new RSACryptoServiceProvider(_keyParameters)) { var document = this.ToXmlDocument(); var signer = new SignaturePropertiesSignedXml(document, _signatureId, _propertiesId) { SigningKey = key }; var reference = new Reference(string.Empty); reference.AddTransform(new XmlDsigEnvelopedSignatureTransform()); signer.AddReference(reference); if (SignatureProperties?.Any() == true) { signer.AddSignatureProperties(SignatureProperties.Select(x => x.SetNamespace(_propertyNs).ToXmlElement())); } signer.ComputeSignature(); var signature = document.ImportNode(signer.GetXml(), true); document.DocumentElement?.AppendChild(signature); return(document.ToXDocument()); } }
public static bool Verify(XDocument document) { var xmlDocument = document.ToXmlDocument(); var signer = new SignaturePropertiesSignedXml(xmlDocument, _signatureId, _propertiesId); var nodeList = xmlDocument.GetElementsByTagName(@"Signature"); signer.LoadXml((XmlElement)nodeList[0]); using (var key = new RSACryptoServiceProvider(_keyParameters)) return(signer.CheckSignature(key)); }