Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用SP公共证书加密SAML 2.0断言-组件空间_C#_Xml_Encryption_Saml 2.0 - Fatal编程技术网

C# 使用SP公共证书加密SAML 2.0断言-组件空间

C# 使用SP公共证书加密SAML 2.0断言-组件空间,c#,xml,encryption,saml-2.0,C#,Xml,Encryption,Saml 2.0,我理解(大部分)SAML过程,因为我在WIF.NET4.5中使用组件空间之前编写了它 我不明白的是如何使用SP的证书加密XML断言。我发现的只是“它在低级api项目中”,但我找不到它 在SendSAMLResponse方法中,我使用我的pfx对证书进行签名。如何使用SP的公共证书将断言加密到元素 我知道你可以使用“高级API”的方式,你可以在saml.config文件中设置一些值来加密它,但是我必须添加更多的属性,我不认为我可以使用“高级API”的方式 ComponentSpace.SAML2.

我理解(大部分)SAML过程,因为我在WIF.NET4.5中使用组件空间之前编写了它

我不明白的是如何使用SP的证书加密XML断言。我发现的只是“它在低级api项目中”,但我找不到它

在SendSAMLResponse方法中,我使用我的pfx对证书进行签名。如何使用SP的公共证书将断言加密到元素

我知道你可以使用“高级API”的方式,你可以在saml.config文件中设置一些值来加密它,但是我必须添加更多的属性,我不认为我可以使用“高级API”的方式


ComponentSpace.SAML2.Assertions.EncryptedAssertion类支持加密和解密SAML断言

在代码中,替换以下行:

samlResponse.Assertions.Add(samlAssertion);
与:

如果改用SAML高级API,那么在SAML配置sam.config文件中,您所要做的就是指定服务提供商的证书,并加密SAML断言

例如,您的saml.config将包括:

<PartnerServiceProvider Name="urn:componentspace:ExampleServiceProvider" 
                        EncryptAssertion="true" 
                        PartnerCertificateFile="sp.cer"

我们提供的高级API ExampleIdentityProvider和MVCEExampleIdentityProvider项目演示了这一点。

稍后我将试用此功能-谢谢。为什么我把你放在这里,我想把“saml.config”文件放在项目的另一个文件夹中,而不是放在根目录中。我知道配置文件会自动在同一个文件夹中查找.pfx和.cer,但我不知道如何告诉
断言
对象在该文件夹中查找。示例-
/rootProject/saml/saml.config
在应用程序的web.config中,可以包含一个应用程序设置,该设置指定saml.config路径。如果您没有相对较新的产品版本,则可能没有此功能。有关更多详细信息,请发送电子邮件给我们。
// Encrypt the SAML assertion using the service provider's public key.
// Loading the x509Certificate is not shown but it could be loaded from a .CER file.        
EncryptedAssertion encryptedAssertion = new EncryptedAssertion(samlAssertion, x509Certificate);

// Add the encrypted assertion to the SAML response.        
samlResponse.Assertions.Add(encryptedAssertion);
<PartnerServiceProvider Name="urn:componentspace:ExampleServiceProvider" 
                        EncryptAssertion="true" 
                        PartnerCertificateFile="sp.cer"
SAMLIdentityProvider.InitiateSSO(Response, userName, attributes, targetUrl, partnerSP);