WCF 添加X509证书加密
1.先在服务器添加证书 makecert.exe -sr LocalMachine -ss My -a sha1 -n CN=TestServer -sky exchange -pe
2.设置证书的权限,everyone添加读取权限
3.服务器端配置
<security mode="Message"> <message clientCredentialType="Certificate" /> </security> <identity> <certificateReference storeName="My" x509FindType="FindBySubjectName" findValue="SkywindServer" /> </identity> <clientCertificate> <authentication certificateValidationMode="None" />这里设置成None因为我们创建的是不受信任的证书 </clientCertificate> <serviceBehaviors> <behavior name="BasicServiceBehavior"> <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" /> <serviceDebug includeExceptionDetailInFaults="false" /> <serviceCredentials> <clientCertificate> <authentication certificateValidationMode="None" /> </clientCertificate> <serviceCertificate findValue="SkywindServer" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" /> </serviceCredentials> </behavior> </serviceBehaviors>
4.客户端配置
<behaviors> <endpointBehaviors> <behavior name="CustomBehavior"> <clientCredentials> <!--客户端证书--> <clientCertificate findValue="Skywind" storeName="My" storeLocation="LocalMachine" x509FindType="FindBySubjectName"/> <serviceCertificate> <authentication certificateValidationMode="None"/> </serviceCertificate> </clientCredentials> </behavior> </endpointBehaviors> </behaviors>