[英]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
使用IClientMessageInspector
上BeforeSendRequest
,我想也加密。 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.