C# https客戶端獲取證書的工具方法
阿新 • • 發佈:2017-07-18
cas cer flag data- 附加 1-1 plain start html
1. 導入證書到個人計算機中
2. 獲取證書
- 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客戶端獲取證書的工具方法