1. 程式人生 > >C# https客戶端獲取證書的工具方法

C# https客戶端獲取證書的工具方法

cas cer flag data- 附加 1-1 plain start html

1. 導入證書到個人計算機中
技術分享


2. 獲取證書

[csharp] view plain copy print?
  1. private static X509Certificate2 GetSentosaCertificate()
  2. {
  3. X509Store userCaStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
  4. try
  5. {
  6. userCaStore.Open(OpenFlags.ReadOnly);
  7. X509Certificate2Collection certificatesInStore = userCaStore.Certificates;
  8. X509Certificate2Collection findResult = certificatesInStore.Find(X509FindType.FindBySubjectName, "*.sentosa.com.sg", true);
  9. X509Certificate2 clientCertificate = null;
  10. if (findResult.Count == 1)
  11. {
  12. clientCertificate = findResult[0];
  13. }
  14. else
  15. {
  16. throw new Exception("Unable to locate the correct client certificate.");
  17. }
  18. return clientCertificate;
  19. }
  20. catch
  21. {
  22. throw;
  23. }
  24. finally
  25. {
  26. userCaStore.Close();
  27. }
  28. }


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客戶端獲取證書的工具方法