繁体   English   中英

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

[英]Encrypting custom header - WCF - WSHttpBinding - Message Security

我有一个WCF服务,该服务在WSHttpBinding中使用security mode="Message"clientCredentialType="None" 我添加了自定义MessageHeader使用IClientMessageInspectorBeforeSendRequest ,我想也加密。 可能吗?

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

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

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

这可以通过指定服务证书来完成。 默认情况下,使用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();
}

结果。
在此处输入图片说明 请随时告诉我是否有什么我可以帮助的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM