The XML does not contain a signature.

Hi, I have a case must to have to use our IDP to imprement SSO.
I use the the sample code “SAML2ServiceProvider” in LowLevelAPI

I trace the code and get the exception message "The XML does not contain a signature. “
The error code in AssertionConsumerService.aspx.cs is
if (!SAMLMessageSignature.Verify(samlResponseXml, x509Certificate))

I think maybe I use the wrong certificate to decrypt the XML at first time.
But I try to use the online tool “<a href=“””>
It’s can be decrypted.

So, my question is what exception message mean?
Does it mean it something wrong when is decrypt the XML?

thanks for your help.

Hi Chris
We recommend using the SAML high-level API wherever possible as it’s much easier to use.
It’s possible that the SAML assertion rather than the SAML response is signed.
If SAMLMessageSignature.IsSigned returns true then you know the SAML response is signed and you can attempt to verify it by calling SAMLMessageSignature.Verify.
Otherwise, you can call SAMLResponse.GetSignedAssertion.

// Verify the SAML assertion signature and deserialize it.
SAMLAssertion samlAssertion = samlResponse.GetSignedAssertion(x509Certificate);

Thanks for your reply. I have some reason that I could not use the High Level API.
I check the SAMLResponse, I saw the XML contect as below.

<samlp:Response xmlns:samlp=“urn:oasis:names:tc:SAML:2.0:protocol” xmlns:ds=“<a href=“””>“ xmlns:saml=“urn:oasis:names:tc:SAML:2.0:assertion” xmlns:xenc=”<a href=“”“>” Destination=“<a href=“http://localhost:51394/SAML2ServiceProvider/SAML/AssertionConsumerService.aspx?binding=urn%3Aoasis%3Anames%3Atc%3ASAML%3A2.0%3Abindings%3AHTTP-POST””>http://localhost:51394/SAML2ServiceProvider/SAML/AssertionConsumerService.aspx?binding=urn%3Aoasis%3Anames%3Atc%3ASAML%3A2.0%3Abindings%3AHTTP-POST" ID=“jggkicdfneajjdjajcdkdaobcaoelbiihkkkgfim” InResponseTo=“_bc7a60eb-1143-41b8-b74c-11586b70a489” IssueInstant=“2018-03-21T07:15:30.911Z” Version=“2.0”>
<samlp:StatusCode Value=“urn:oasis:names:tc:SAML:2.0:status:Success” />
<xenc:EncryptedData Type=“”>">
<xenc:EncryptionMethod Algorithm=“<a href=“””>" />
<xenc:EncryptionMethod Algorithm=“<a href=“””>" />

So, I think decrypt it by using my certificate firstly. So I coding as below

samlResponse = new SAMLResponse(samlResponseXml);

EncryptedAssertion encryptedAssertion = samlResponse.GetEncryptedAssertion();
SAMLAssertion samlAssertion = encryptedAssertion.Decrypt(x509Certificate.PrivateKey);

It’s work now, I decrypt the SAMLResponse succelly. And next step I think I need to verify signature.
How do I do?

Instead of encryptedAssertion.Decrypt, call encryptedAssertion.DecryptToXml.

XmlElement samlAssertionElement = encryptedAssertion.DecryptToXml(spX509Certificate.PrivateKey);

if (SAMLAssertionSignature.IsSigned(samlAssertionElement))
if (!SAMLAssertionSignature.Verify(samlAssertionElement, idpX509Certificate))
// Handle failed signature verification.
SAMLAssertion samlAssertion = new SAMLAssertion(samlAssertionElement);
// Handle unsigned assertion.