C# azure上pkcs#12的呼叫服务

C# azure上pkcs#12的呼叫服务,c#,azure,ssl,certificate,C#,Azure,Ssl,Certificate,我收到了一个P12证书,我需要使用它从Azure worker角色调用Web服务。我上传了证书,将其转换为pem文件并添加到programmaticaly中,但我总是在GetRequest中遇到异常: The request was aborted: Could not create SSL/TLS secure channel. 我知道p12也包含一个私钥,所以这可能是问题所在 String strPem = "***valid PEM in BAS64***"; Uri uriGatewa

我收到了一个P12证书,我需要使用它从Azure worker角色调用Web服务。我上传了证书,将其转换为pem文件并添加到programmaticaly中,但我总是在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();
我找到了解决办法

创建X509证书并使用导入方法导入p12证书文件

var certificateFileName = Server.MapPath("~/Cert/cert.pfx");
X509Certificate2 cert = new X509Certificate2();
cert.Import(certificateFileName,"pw",X509KeyStorageFlags.PersistKeySet);

现在它可以工作了…

您在哪里上传了证书,以哪种格式?它应该上传到管理证书部分,并且应该是cer文件格式。我在Azure管理门户的云服务>证书中上传了它。我上传了它作为一个pfx。如果我将其转换为cer,它会从我理解的情况中释放私钥。。。(这可能就是问题所在)。注意,我在azure管理门户和通过PEM的代码中都尝试了证书。这两种情况都不起作用。。。