简体   繁体   English

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

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

I have an WCF service, which is configured in WSHttpBinding , using security mode="Message" , with clientCredentialType="None" . 我有一个WCF服务,该服务在WSHttpBinding中使用security mode="Message"clientCredentialType="None" I'm adding an custom MessageHeader using IClientMessageInspector on BeforeSendRequest and i want to also encrypt it. 我添加了自定义MessageHeader使用IClientMessageInspectorBeforeSendRequest ,我想也加密。 Is it possible? 可能吗?

EDIT: Currently I've added an custom asymmetic engine, which is encrypting, using certificate acquired by: 编辑:目前,我已经添加了一个自定义的不对称引擎,该引擎使用通过以下方式获取的证书进行加密:

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

and decrypting (certificate on server found by thumbprint) specific values, just before writing/reading them to/from header. 并在将它们写入标头/从标头读取之前,解密(通过指纹找到的服务器上的证书)特定值。 Is it a good way to do it? 这是一个好方法吗? Can it be done better? 能做得更好吗?

This could be completed by specifying a service certificate. 这可以通过指定服务证书来完成。 By default, the message security is implemented by using Windows credential. 默认情况下,使用Windows凭据实现邮件安全性。

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

So just we need to do is specify a service certificate for encrypting and signing. 因此,我们需要做的是指定用于加密和签名的服务证书。

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();
}

Result. 结果。
在此处输入图片说明 Feel free to let me know if there is anything I can help with. 请随时告诉我是否有什么我可以帮助的。

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

相关问题 具有证书消息安全性的WCF wsHttpBinding - WCF wsHttpBinding with certificate message security WCF / wsHttpBinding / 消息安全 - BadTokenRequest - WCF / wsHttpBinding / Message Security - BadTokenRequest WCF wsHttpBinding安全性错误 - WCF wsHttpBinding Security Error 具有WsHttpBinding的WCF安全TransportWithMessageCredentials - WCF security TransportWithMessageCredentials with WsHttpBinding WCF与WSHttpBinding,消息安全性,clientCredentialType =“UserName”Cerificate SelfHosted问题 - WCF with WSHttpBinding, Message Security, clientCredentialType=“UserName” Cerificate SelfHosted Issue 使用wsHttpBinding和Message Security与客户端凭据类型窗口负载平衡WCF - load balancing WCF with wsHttpBinding and Message Security with client credentials type windows 客户端和服务器上都有证书的WCF(消息安全性和wsHttpBinding) - WCF with certificates on both Client and Server (Message security and wsHttpBinding) wsHttpBinding消息安全性 - wsHttpBinding Message Security WCF-具有用户名确认和消息的wsHttpBinding-错误消息“处理消息中的安全令牌时发生错误” - WCF - wsHttpBinding with UserName Autentication and Message - error message “An error occurred when processing the security tokens in the message” 使用wsHttpBinding并且没有Windows安全性的WCF会话 - WCF sessions with a wsHttpBinding and without windows security
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM