最近在做一个数据对接业务,对方接口安全性要求很高,接口需要使用证书私钥进行签名。每次访问接口都会被要求输入证书私钥密码,浏览器访问还能忍受,但是访问接口也会弹框(如图所示)实在不能忍(PS:客户也不接受)。
问题:请问各位大神,如何才能默认输入密码,不要弹框?
现有代码如下:
static string Request()
{
try
{
StreamReader sr = null;
HttpWebResponse wr = null;
HttpWebRequest hp = (HttpWebRequest)WebRequest.Create("https://URL?dataId=0&resType=xml");
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
var cert = new X509Certificate2("******有限公司_签名证书.cer", "12345678", X509KeyStorageFlags.DefaultKeySet| X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
cert.PrivateKey = AsymmetricAlgorithm.Create("12345678");
hp.ClientCertificates.Add(cert);
wr = (HttpWebResponse)hp.GetResponse();
sr = new StreamReader(wr.GetResponseStream(), System.Text.Encoding.GetEncoding("GBK"));
return sr.ReadToEnd();
}
catch (Exception ex)
{
Console.Write("错误:{0}", JsonConvert.SerializeObject(ex));
}
return "";
}