Decrypt SAML Response with X.509 Certificate and P

2019-09-21 03:47发布

I am trying to decrypt a SAML Response with a X.509 Certificate and the Private Key (both stored in local drive) using .NET.

This is the XML file to decrypt:

<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" Version="2.0" ID="mFCXf3nW6C7tzReKMQjpJ81L9Yu" IssueInstant="2019-09-11T13:29:01.254Z" Destination="https://test.com/sso.aspx" >
  <saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">saml.test.com</saml:Issuer>
  <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
    <ds:SignedInfo>
      <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
      <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
      <ds:Reference URI="#mFCXf3nW6C7tzReKMQjpJ81L9Yu">
        <ds:Transforms>
          <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
          <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
        </ds:Transforms>
        <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
        <ds:DigestValue>ejzCFmHiMyh07qJB88=</ds:DigestValue>
      </ds:Reference>
    </ds:SignedInfo>
    <ds:SignatureValue> FEmLZgeML744VSl 2H5KrPBSBPuHnVtVzo5APGqy/D4YPqgEpW5kOhV3aDpV6ZH/K0FBonrYFaoDn7eG4rIWoDhJAhdh pas9O70JgqIxi1e6fPLG0zWMCEVDhD0VKK6DPdJeesRxuyqL6ZoQ9oe7FvIsnkGu/QxWVwl2DZZD 73Z/brHijqXg3sRQGsgeZlsnH5JyBj/ADJZgCablLXHBr75wQmZi1AvsLE9e/h3+U7RMalqqx0TI bo8OXA/9ZTdJnF9zWU9hYcFhHBTPF9fGDdsFIg== </ds:SignatureValue>
    <ds:KeyInfo>
      <ds:X509Data>
        <ds:X509Certificate> MIIGojCCBYqgAwIBA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>
      <ds:KeyValue>
        <ds:RSAKeyValue>
          <ds:Modulus> oHlWBuw1PvoVYX3NL9qkYz33NyU34PUI6BWIiUiab8zh/qe17nAAMCgHxJYw5g2h8WJiZBhDPdlr pREMLHoMd6xkgXFKWVUZh+TE/Kxp7D1YCvvDd0WlOqvvrEkuPi1iRBXQLj3xopwKY7INzvwnKykw QxcV+y50B1E+oV8oHD0c+ZTN1NRGWCfFLPoRhIShIG5QaPpQy1h9E74BO2VohQPhkj9hwRC7qTIb pKXztQi0T2BERs/iDxEEHa9xzY0AjBEqvUoZ8iqbd4IoqcF0+ryWwP+rCR9FPy43aW+U0mvYn2KT N+MA0JSdhLrAD9h1KKQIpXnL64W7QDexiJaXUQ== </ds:Modulus>
          <ds:Exponent>AQAB</ds:Exponent>
        </ds:RSAKeyValue>
      </ds:KeyValue>
    </ds:KeyInfo>
  </ds:Signature>
  <samlp:Status>
    <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
  </samlp:Status>
  <saml:EncryptedAssertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
    <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Type="http://www.w3.org/2001/04/xmlenc#Element" >
      <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc" />
      <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
        <xenc:EncryptedKey>
          <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p" />
          <xenc:CipherData>
            <xenc:CipherValue>QcN9dKFTAxtXQEWlh20el91EDQy4bTgX2TNDZnqgS2MfCHngdFPXEzmQC3v7w7YTxrHVx8L/aOee YjJK1CC63E1RcD4qKUmrWHDqqGO3RszSMcdWeKDndzlFbj9Z3TsFmVmVQEsL/pryg6nJAYd6jQrC FLzHlTSUKqXxS9Rl9VI=</xenc:CipherValue>
          </xenc:CipherData>
        </xenc:EncryptedKey>
      </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XGA7eiENW3r SDM+5dlam9f9mNf36QTvI4VIQzpguQ62HoFl0k2w5VAyCB5auwMsdp2MYvCOoVXo2S/Ld0LpDaeL DcKlM7w9b4TsuaDhESgGGD+270g0Ub6e0Af8jRi0a0kYy782t4hCF8Ha2xmHeZoOexxt0dIF+pZT 58fcnS1kRQRIpaFm67TNZ3exp7T2PfD/NOha5b63yXIFER8HoJp3C/MVx3wzRqZkfSZ1ejx1ugXG E94h0ggY8lR2HAhqvLTSvlEZWvCXpIsToW+TGdFR54FtZ2lMzctN68z87IzHNZovg1Lugt93F5qj FoBwD4ws1t6yK11wZUvNQ0kqOnpwaC8wpYrLo9bumGKm5x/1pKc6V28ne7aED9aU37cvka0BNib0 0Qb8crfR3XxnLPhkqMXWSPkGpxIPr6RdbAskF1RY1fJpOsro1dxrXfScxOVfRl6TWCPZlJkUKQtL w9bLc0Fb6FcNMJ+276MoTII58POamQ==</xenc:CipherValue>
      </xenc:CipherData>
    </xenc:EncryptedData>
  </saml:EncryptedAssertion>
</samlp:Response>

0条回答
登录 后发表回答