日期:2014-05-19  浏览次数:21206 次

C#访问https(SSL)时自动选择证书
悬赏!

编写C#访问   https   时需要指定证书。

如何才能用程序从系统中取得和服务器对应的证书?

这应该是SSL握手的问题,可应该在什么地方、用什么方法取得服务器的证书呢?

急!!!!!

谢谢!



------解决方案--------------------
there is always only one certificate for one server. and it 's pushed to your client side. you can only chose whether to trust it or not.

for the client side certificate, you can manually assign to the request if you have more than 2 certificates.

if you 'd like to access the certificate information, insert your code into the implementation of CheckValidationResult method.
ther is a certificate parameter for you to inspect.



------解决方案--------------------
不好意思,最近一直忙着做PKI很少来这里, 服务器证书不需要获取得,IIS自动会请求客户端发送证书的. 具体看相关文章.
只需要客户端选择相应的由共同CA中心发布的客户端验证证书即可.

X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

store即获取了操作系统内安装的用户证书列表, 然后遍历读取就可以了.