Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C私钥丢失-证书与私钥一起安装_C#_Asp.net - Fatal编程技术网

C# C私钥丢失-证书与私钥一起安装

C# C私钥丢失-证书与私钥一起安装,c#,asp.net,C#,Asp.net,iam正在编写代码以访问另一台服务器上的服务 证书是用私钥安装在我的服务器上的 当我运行测试时 if (cer.HasPrivateKey) { Response.Write("OK"); } else { Response.Write("Nooo"); } 我得到ok=因此证书有私钥 但是当我运行整个代码时

iam正在编写代码以访问另一台服务器上的服务

证书是用私钥安装在我的服务器上的

当我运行测试时

if (cer.HasPrivateKey)
            {
                Response.Write("OK");

            }
            else
            {
                Response.Write("Nooo");
            }
我得到ok=因此证书有私钥

但是当我运行整个代码时

 try
        {


            //  ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            HttpWebRequest httpWReq =
                 (HttpWebRequest)WebRequest.Create("https://gw.bisan.com/api/apdemo_6");

            Encoding encoding = new UTF8Encoding();
            string postData = @"{""user"":""cube"",""password"":""258970"",""command"":""table"",""table"":""currency"",""filters"":[{""field"":""code"",""operation"":""!\u003d"",""value"":""01""}],""fields"":[""symbol"",""rate""]}";
            byte[] data = encoding.GetBytes(postData);

            httpWReq.ProtocolVersion = HttpVersion.Version11;
            httpWReq.Method = "POST";
            httpWReq.ContentType = "application/json";//charset=UTF-8";


            var certificate = @"\www.cube-its.com.pfx";
            X509Certificate2 cer = new X509Certificate2(new X509Certificate2(Server.MapPath(certificate), "XXXX"));

            httpWReq.ClientCertificates.Add(cer);

            Response.Write(cer.PrivateKey.ToString());
            if (cer.HasPrivateKey)
            {
                Response.Write("OK");

            }
            else
            {
                Response.Write("Nooo");
            }

            httpWReq.ContentLength = data.Length;



            Stream stream = httpWReq.GetRequestStream();
            stream.Write(data, 0, data.Length);
            stream.Close();

            HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();

            string s = response.ToString();
            StreamReader reader = new StreamReader(response.GetResponseStream());
            String jsonresponse = "";
            String temp = null;
            while ((temp = reader.ReadLine()) != null)
            {
                jsonresponse += temp;
            }

            Response.Write("Json Response : " + jsonresponse);

        }
        catch (WebException ex1)
        {
            { Response.Write("Exception 2 : " + ex1.Message); }
        }
        catch (Exception ex) { Response.Write("Exception : " + ex.Message); }
我总是收到服务器错误400错误请求

当我打电话给公司时,他们说请求缺少私钥


那么我该怎么办呢?'thanx

我希望这不是.pfx文件的真实密码如果安装了证书,为什么不使用证书存储?从Store加载问题是证书安装在托管服务器上不是我获得证书的,所以是相同的方法吗?