现在我完全坚持如何从我的证书生成Keyinfo并进入SAML Schema类。我的互联网搜索几乎毫无结果。我没有使用任何第三方组件,也无法使用。我需要使用可用的加密.net类直接c#,没有WIF。我正在尝试使用Assertion Encryption将我的SSO身份提供程序的工作代码库调整为支持断言加密的代码库。有人能指出一些资源来解释如何去做吗?
我需要生成SAML2令牌的以下部分:
<saml:EncryptedAssertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<X509Data>
<X509Certificate>
MIIEyzCCBDSgAwIBAgIQJw04cdtYORKGDtzhzZj1gjANBgkqhkiG9w0BAQUFADCBujEfMB0GA1UEChMWVmVyaVNpZ24gVHJ1c3QgTmV0d29yazEXMBUGA1UECxMOVmVyaVNpZ24sIEluYy4xMzAxBgNVBAsTKlZlcmlTaWduIEludGVybmF0aW9uYWwgU2VydmVyIENBIC0gQ2xhc3MgMzFJMEcGA1UECxNAd3d3LnZlcmlzaWduLmNvbS9DUFMgSW5jb3JwLmJ5IFJlZi4gTElBQklMSVRZIExURC4oYyk5NyBWZXJpU2lnbjAeFw0wODA2MDQwMDAwMDBaFw0xMTA2MDQyMzU5NTlaMIHPMQswCQYDVQQGEwJVUzERMA8GA1UECBMISWxsaW5vaXMxEDAOBgNVBAcUB0NoaWNhZ28xEzARBgNVBAoUCkJTV0lGVCBMTEMxNTAzBgNVBAsULElUVGVybXMgb2YgdXNlIGF0IHd3dy52ZXJpc2lnbi5jb20vcnBhIChjKTAwMTMwMQYDVQQLFCpUZXJtcyBvZiB1c2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iWGyYipM8Weg==
</X509Certificate>
</X509Data>
</KeyInfo>
<CipherData>
<CipherValue>
PVKYYTNGIjuYQCCTyS4LriEyIq1njqotkyJvmoO+WvQSc34plBcfUvGS/zDoKj329528gwctTikXxsCPXJJvISdFdew/t+qIVISnob5TzxSjmhlWJVHOzhx2UAbfqxvVkpCPIJr2uskYzRdeHez77g1UZe82BTGGG9S2SXZI9fM=
</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>
QQeOIBWvGnI7dYR2o2TMGdh6NfG3V26Y2USKNuj5j3z5woUTu8wYR77ddSMlQjZ+fL6dB3Ozr6RzPYOevkX67uXWAlGVOOcz0OH48RajJBfGRZNHWHQfjF4liLsLZ9yOj2rMiXsEBZzVjkpxBQ5kb3/a3Mfi6xQb8/kQnrBpDyaidP2VVW1AmplqV9aYyWgM+CBTXndkFY1xS52YqmWIP5AYT04Hl5m/e3SmY0/QmUWBV+di75VFP3yv+iWtAqjZoxEtmiGXdzZLqDbbVUgbvzZjLl2oEfXDh/7gEslb3aB0wx5iK7n4vCeSSZYJxrndbNPIpqRXL+1bgAdrHdiTVrDYfsrK3GRp3nEjqxRFrAald/GyrU1RH2q3q4qOvwLpHAE1oD0SekErDM8With5tZ3a3IUhaUu6gVIp2nCWRVC3PzdRGpld6ZRJ03h8QFGqPuabbbFWPJJf233N0yuueB52s5gw3RPiUYKEQVoqkh0ZkXUUDmvXdr6cE4z2ztCX5W4rplJ3j8qowScilmKGveU6HIM+1KBKD9Xgw2ph1YQ4CTLKGEl1VNmvjGIjvLBmr6oj453BCnJZ/IFVhCScdDn+4yYG9SKenzuarv+//ZnoUkybOQDNvzyFiV3/pT1xIPXN6MQWLqZVO3OmoTdGdhFcKHbUxRwVd4GJeri64h0fCsC8Po4HG+FtbaJtoJRmGEfaNqnv7S8lapxLjAINon6XO6uyFsdEGaLpc5zx0oVrY/rNrZGerVXb2y91dp89A/y3Z/pdlXCDRr5aa4UYQ4BELHHzTqNa9Low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yL9j2Y65o6Ip5Ps1GzV51gnO97PCN6P+pB9iMiy9RNlFf32F1ycZ2EZ78BQGPfpA91QzTRO/hsL9BsF66LIWPaMUSGKdN9sxzY3V8HxxE6SH8wDq+1c5kpfHdWQBVjQqWruTKbAbc0sO7rkZvfW3bILst7F6Uqn4nHZ9g23KtyXzEDWZkXQW3U2CXEpytUEfEn9X2xToIJZVbcr6V0bxABw7GspghilkmXrKyKqjJ9lUQZq1kN5Za/tVdFh2WQMeztqwTibi9DZyZHh/h43ILC/Kv7RTlQ18TUi0kQS8Ll1Rx1yQ9atpk3XRSTQZBMc77nkzOkApIgRh+gHyBeUG3tDdKyHId
</CipherValue>
</CipherData>
</EncryptedData>
</saml:EncryptedAssertion>
到目前为止,我已经达到了这一点:
EncryptedElementType encryptedAssertion = new EncryptedElementType();
EncryptedDataType encryptedData = new EncryptedDataType();
encryptedData.Type = "http://www.w3.org/2001/04/xmlenc#Element";
EncryptionMethodType encryptionMethod = new EncryptionMethodType();
encryptionMethod.Algorithm = "http://www.w3.org/2001/04/xmlenc#aes128-cbc";
KeyInfoType keyInfoRoot = new KeyInfoType();
EncryptedKeyType encryptedKey = new EncryptedKeyType();
X509Certificate2 encryptingCert = null;
if (findValueSigning.ToString() == findValueEncryption.ToString()) encryptingCert = signingCert;
else encryptingCert = GetCertBySerialNumber(storeLocation, storeName, findType, findValueEncryption);
KeyInfo keyInfo = new KeyInfo();
KeyInfoX509Data keyData = new KeyInfoX509Data(encryptingCert);
keyInfo.AddClause(keyData);
//keyInfoRoot.Items = object[] { encryptedKey };
encryptedData.EncryptionMethod = encryptionMethod;
encryptedData.KeyInfo = keyInfoRoot;
encryptedAssertion.EncryptedData = encryptedData;
response.Items = new EncryptedElementType[] { encryptedAssertion };