[英]Encrypting custom header - WCF - WSHttpBinding - Message Security
我有一個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>
並在將它們寫入標頭/從標頭讀取之前,解密(通過指紋找到的服務器上的證書)特定值。 這是一個好方法嗎? 能做得更好嗎?
這可以通過指定服務證書來完成。 默認情況下,使用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.