EndpointIdentity.CreateRsaIdentity 方法

定义

创建一个 RSA 标识。

重载

CreateRsaIdentity(X509Certificate2)

使用指定的 X.509 证书创建一个 RSA 标识。

CreateRsaIdentity(String)

使用指定的公钥创建一个 RSA 标识。

注解

通过此标识连接到终结点的安全 WCF 客户端将验证在服务器提供的众多声明中是否具有一个包含用于构建此标识的 RSA 公钥的声明。

这些静态方法之一通过调用其构造函数 RsaEndpointIdentity 创建 RsaEndpointIdentity 的实例。

CreateRsaIdentity(X509Certificate2)

使用指定的 X.509 证书创建一个 RSA 标识。

public:
 static System::ServiceModel::EndpointIdentity ^ CreateRsaIdentity(System::Security::Cryptography::X509Certificates::X509Certificate2 ^ certificate);
public static System.ServiceModel.EndpointIdentity CreateRsaIdentity (System.Security.Cryptography.X509Certificates.X509Certificate2 certificate);
static member CreateRsaIdentity : System.Security.Cryptography.X509Certificates.X509Certificate2 -> System.ServiceModel.EndpointIdentity
Public Shared Function CreateRsaIdentity (certificate As X509Certificate2) As EndpointIdentity

参数

certificate
X509Certificate2

一个包含 RSA 标识的证书的 X509Certificate2

返回

EndpointIdentity

一个与指定的 EndpointIdentity 关联的 certificate

例外

certificatenull

certificate 不是一个 RSA 证书。

示例

下面的代码演示如何调用此方法。

public static void CreateRSAIdentity()
{
    // Create a ServiceHost for the CalculatorService type. Base Address is supplied in app.config.
    using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService)))
    {
        // The base address is read from the app.config.
        Uri dnsrelativeAddress = new Uri(serviceHost.BaseAddresses[0], "dnsidentity");
        Uri certificaterelativeAddress = new Uri(serviceHost.BaseAddresses[0], "certificateidentity");
        Uri rsarelativeAddress = new Uri(serviceHost.BaseAddresses[0], "rsaidentity");

        // Set the service's X509Certificate to protect the messages.
        serviceHost.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine,
                                                                  StoreName.My,
                                                                  X509FindType.FindBySubjectDistinguishedName,
                                                                  "CN=identity.com, O=Contoso");
        //Cache a reference to the server's certificate.
        X509Certificate2 servercert = serviceHost.Credentials.ServiceCertificate.Certificate;

        //Create endpoints for the service using a WSHttpBinding set for anonymous clients.
        WSHttpBinding wsAnonbinding = new WSHttpBinding(SecurityMode.Message);
        //Clients are anonymous to the service.
        wsAnonbinding.Security.Message.ClientCredentialType = MessageCredentialType.None;
        //Secure conversation (session) is turned off.
        wsAnonbinding.Security.Message.EstablishSecurityContext = false;

        //Create a service endpoint and change its identity to the DNS for an X509 Certificate.
        ServiceEndpoint ep = serviceHost.AddServiceEndpoint(typeof(ICalculator),
                                                            wsAnonbinding,
                                                            String.Empty);
        EndpointAddress epa = new EndpointAddress(dnsrelativeAddress, EndpointIdentity.CreateDnsIdentity("identity.com"));
        ep.Address = epa;

        //Create a service endpoint and change its identity to the X509 certificate's RSA key value.
        ServiceEndpoint ep3 = serviceHost.AddServiceEndpoint(typeof(ICalculator), wsAnonbinding, String.Empty);
        EndpointAddress epa3 = new EndpointAddress(rsarelativeAddress, EndpointIdentity.CreateRsaIdentity(servercert));
        ep3.Address = epa3;

注解

连接到此标识的终结点的安全 WCF 客户端验证服务器提供的声明是否包含从用于构造此标识的证书中获取的 RSA 公钥的声明。

此静态方法通过调用其构造函数 RsaEndpointIdentity 创建 RsaEndpointIdentity 的实例。

适用于

CreateRsaIdentity(String)

使用指定的公钥创建一个 RSA 标识。

public:
 static System::ServiceModel::EndpointIdentity ^ CreateRsaIdentity(System::String ^ publicKey);
public static System.ServiceModel.EndpointIdentity CreateRsaIdentity (string publicKey);
static member CreateRsaIdentity : string -> System.ServiceModel.EndpointIdentity
Public Shared Function CreateRsaIdentity (publicKey As String) As EndpointIdentity

参数

publicKey
String

RSA 标识的公钥。

返回

EndpointIdentity

一个与指定的 EndpointIdentity 关联的 publicKey

例外

publicKeynull

注解

通过此标识连接到终结点的安全 WCF 客户端将验证在服务器提供的众多声明中是否具有一个包含用于构建此标识的 RSA 公钥的声明。

此静态方法通过调用其构造函数 RsaEndpointIdentity 创建 RsaEndpointIdentity 的实例。

适用于