首页 > 代码库 > C# https客户端获取证书的工具方法
C# https客户端获取证书的工具方法
1. 导入证书到个人计算机中
2. 获取证书
[csharp] view plain copy
print?
- private static X509Certificate2 GetSentosaCertificate()
- {
- X509Store userCaStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
- try
- {
- userCaStore.Open(OpenFlags.ReadOnly);
- X509Certificate2Collection certificatesInStore = userCaStore.Certificates;
- X509Certificate2Collection findResult = certificatesInStore.Find(X509FindType.FindBySubjectName, "*.sentosa.com.sg", true);
- X509Certificate2 clientCertificate = null;
- if (findResult.Count == 1)
- {
- clientCertificate = findResult[0];
- }
- else
- {
- throw new Exception("Unable to locate the correct client certificate.");
- }
- return clientCertificate;
- }
- catch
- {
- throw;
- }
- finally
- {
- userCaStore.Close();
- }
- }
3. 将证书附加在http请求中即可
http://www.woaipu.com/shops/zuzhuan/61406
http://www.znds.com/tv-967956-1-1.html
http://www.znds.com/tv-967958-1-1.html
C# https客户端获取证书的工具方法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。