/// <summary> /// Sign and build. /// </summary> /// <param name="certificate"></param> /// <param name="digestMethod"></param> /// <param name="canonicalizationMethod"></param> /// <returns></returns> public ResponseType SignAndBuild(X509Certificate2 certificate, SignatureAlgorithms signatureAlgorithm, CanonicalizationMethods canonicalizationMethod) { foreach (var assertion in _response.Items.Where(i => i is AssertionType).Cast <AssertionType>()) { var assertionSigned = new SamlSignedRequest(assertion.SerializeToXmlElement(), certificate, signatureAlgorithm, canonicalizationMethod); assertionSigned.ComputeSignature(assertion.ID); var assertionSignature = assertionSigned.GetXml().OuterXml.DeserializeXml <SignatureType>(); assertion.Signature = assertionSignature; } var signedRequest = new SamlSignedRequest(_response.SerializeToXmlElement(), certificate, signatureAlgorithm, canonicalizationMethod); signedRequest.ComputeSignature(_response.ID); var signature = signedRequest.GetXml().OuterXml.DeserializeXml <SignatureType>(); _response.Signature = signature; return(_response); }