如何使用节点中的pkcs12证书文件发布呼叫

时间:2019-05-21 11:36:25

标签: .net node.js x509certificate client-certificates

我正在尝试迁移使用pkcs12证书(cert + key)调用后端点的代码。我在.net中这样做:

string PKSC12_SELFCERTPATH = "http://...";
string SELFCERTPWD = "Ipp@9999"

var handler = null;
try
{
    var cert = new X509Certificate2(PKSC12_SELFCERTPATH, SELFCERTPWD);
    handler = new WebRequestHandler();
    handler.ClientCertificates.Add(cert);

    var client = new HttpClient(handler);

    System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(ValidarCertificado);
    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

    var values = new Dictionary<string, string>
    {
        { "appId", LITERAL_APPID },
        { "secret",LITERAL_SECRET }
    };

    var content = new FormUrlEncodedContent(values);

    var response = await client.PostAsync( URL, content);

    var responseString = await response.Content.ReadAsStringAsync();

    json = JObject.Parse(responseString);
}
catch(Exception ex)
{
    ...
}

我们正在使用此库(https://github.com/encharm/x509.js),但是它与crt文件一起使用,¿我们是否需要首先使用密码将我的pkcs12手动导出到crt?

0 个答案:

没有答案