我收到了一个 P12 证书,我需要使用该证书从 Azure 辅助角色调用 Web 服务。我上传了证书,我把它变成了一个 pem 文件并以编程方式添加它,但我总是在 GetRequest 上得到异常:
The request was aborted: Could not create SSL/TLS secure channel.
我知道 p12 还包含一个私钥,所以这可能是问题......
String strPem = "***valid PEM in BAS64***";
Uri uriGateway = new Uri("https://xxxx");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriGateway);
byte[] baPem = Convert.FromBase64String(strPem);
ServicePointManager.Expect100Continue = true;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(AcceptAllCertifications);
X509Certificate2 cert = new X509Certificate2(baPem);
request.Method = "GET";
request.ClientCertificates.Add(cert);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();