您好,登錄后才能下訂單哦!
1. 獲取訪問(wèn)網(wǎng)站需要的證書(shū)
2. 從微軟官網(wǎng)下載“資源工具箱”,其中包括證書(shū)管理工具。
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=17657
安裝完,Windows HTTP 服務(wù)證書(shū)配置工具(WinHttpCertCfg.exe)通常應(yīng)該在C:\Program Files\Windows Resource Kits\Tools文件夾下。
3. 使用CMD命令行,運(yùn)行WinHttpCertCfg.exe工具;
WinHttpCertCfg.exe –g –c LOCAL_MACHINE\MY –i “你的證書(shū)地址” –a “授權(quán)的用戶組/名” –p 密碼
給IIS服務(wù)用戶組授權(quán)并導(dǎo)入證書(shū)。
這樣,就可以在IIS管理,證書(shū)頁(yè)面可以看到剛才導(dǎo)入的證書(shū)。
重啟IIS服務(wù),使剛才的授權(quán)生效。
4. 導(dǎo)出證書(shū)為.CER文件
開(kāi)始—》運(yùn)行—》輸入MMC;打開(kāi)控制臺(tái)
文件—》添加/刪除管理單元
選擇“證書(shū)”,點(diǎn)擊“添加”,選擇“計(jì)算機(jī)賬號(hào)”,“下一步”,“完成”,“確定”
選擇“個(gè)人”—》“證書(shū)”;
右鍵單擊證書(shū),“所有任務(wù)”—》“導(dǎo)出”—》“下一步”—》“下一步”
選擇
,點(diǎn)擊“下一步”,單擊“瀏覽”,輸入要保存的文件名和地址,“下一步”—》“完成”;
導(dǎo)出成功!
5. C#使用證書(shū)進(jìn)行SSL安全通信代碼示例
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- //引用命名空間
- using System.IO;
- using System.Net;
- using System.Net.Security;
- using System.Security.Authentication;
- using System.Security.Cryptography.X509Certificates;
- public partial class ssl : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- //驗(yàn)證服務(wù)器證書(shū)回調(diào)方法
- ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
- //創(chuàng)建HttpWebRequest對(duì)象
- HttpWebRequest https = (HttpWebRequest)HttpWebRequest.Create("https://localhost/restful/test/BBBAAA");
- //創(chuàng)建證書(shū)
- X509Certificate obj509 = new X509Certificate(AppDomain.CurrentDomain.BaseDirectory+"cert\\ccc.cer");//寫(xiě)入正確的證書(shū)路徑(第四步導(dǎo)出的Cer文件)
- //添加證書(shū)到HTTP請(qǐng)求中
- https.ClientCertificates.Add(obj509);
- https.Method = "GET";
- //獲取請(qǐng)求返回的數(shù)據(jù)
- HttpWebResponse response = (HttpWebResponse)https.GetResponse();
- //讀取返回的信息
- StreamReader sr = new StreamReader(response.GetResponseStream(), true);
- int count;
- char[] ReadBuf = new char[1024];
- do
- {
- count = sr.Read(ReadBuf, 0, 1024);
- if (0 != count)
- {
- Label3.Text = new string(ReadBuf);
- }
- } while (count > 0);
- }
- //重寫(xiě)證書(shū)驗(yàn)證方法,總是返回TRUE,解決未能為SSL/TLS安全通道建立信任關(guān)系的問(wèn)題
- public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
- {
- //總是返回TRUE
- return true;
- }
- }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。