加密自定义标头-WCF-WSHttpBinding-邮件安全

时间:2019-07-29 08:57:07

标签: wcf security encryption header

我有一个WCF服务,该服务是在WSHttpBinding中使用security mode="Message"clientCredentialType="None"配置的。我在MessageHeader上使用IClientMessageInspector添加了自定义BeforeSendRequest,并且我也想对其进行加密。可能吗?

编辑: 目前,我已经添加了一个自定义的不对称引擎,该引擎使用通过以下方式获取的证书进行加密:

 <behaviors>
  <endpointBehaviors>
    <behavior>
      <clientCredentials>
        <serviceCertificate>
          <authentication certificateValidationMode="Custom" customCertificateValidatorType="CustomCertificateValidator.CustomCertificateValidator, CustomCertificateValidator"/>
        </serviceCertificate>
      </clientCredentials>
    </behavior>
  </endpointBehaviors>
</behaviors>

并在将特定值写入标头/从标头读取之前,解密(在指纹找到的服务器上的证书)特定值。这是一个好方法吗?可以做得更好吗?

1 个答案:

答案 0 :(得分:0)

这可以通过指定服务证书来完成。默认情况下,使用Windows凭据实现邮件安全性。

WSHttpBinding binding = new WSHttpBinding();
            binding.Security.Mode = SecurityMode.Message;
            binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;

所以我们只需要指定用于加密和签名的服务证书即可。

using (ServiceHost sh = new ServiceHost(typeof(MyService)))
{
    sh.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, "cbc81f77ed01a9784a12483030ccd497f01be71c");

    sh.Open();
    Console.WriteLine("Service is ready....");

    Console.ReadLine();
    sh.Close();
}

结果。
enter image description here 随时让我知道是否有什么可以帮助您的。

相关问题