“对象仅包含密钥对的公共一半。还必须提供私钥。“使用2 .pem和X509和MS Services3.Security

问题描述 投票:1回答:1

这是代码:

using ADPTest.com.adp.hrbws;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Web.Services3.Security;
using Microsoft.Web.Services3.Security.Tokens;
using Microsoft.Web.Services3.Security.Cryptography;

namespace ADPTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create the web service proxy.
            HrbService proxy = new HrbService();

            // Add the Username token.
            UsernameToken usernameToken = new UsernameToken("user@ABC"," ");
            proxy.RequestSoapContext.Security.Tokens.Add(usernameToken);

            // Add the certificate for mutual SSL.
            X509Certificate2 mutualCert = new X509Certificate2 "I:\\auth.pem", " ");
            proxy.ClientCertificates.Add(mutualCert);

            // Sign the message using the signing certificate.
            X509Certificate2 signCert = new X509Certificate2("I:\\soap.pem", " ");
            X509SecurityToken signatureToken = new X509SecurityToken(signCert);
            MessageSignature signature = new MessageSignature(signatureToken);
            proxy.RequestSoapContext.Security.Elements.Add(signature);

我认为mutualCert,auth,是我的公共证书,signCert,SOAP,是我的私人证书,但我真的不确定。我从一种(网络服务)食谱中获取代码......网络服务说他们不看密码。

错误消息是:

“对象仅包含密钥对的公共一半。还必须提供私钥。”

certificate x509 pem key-pair
1个回答
2
投票

您需要将.pem文件转换为.pfx才能使用.Net框架才能使用它。 .pfx将包含公钥和私钥。您可以使用OpenSSL将ADP发送给您的.pem文件转换为.pfx文件。

http://www.openssl.org/

mutualCert是用于连接到ADP的SSL证书signCert用于SOAP / webservice调用

我已经在与ADP的界面上工作了几个月,我仍然遇到问题。

希望这有助于-Doug

© www.soinside.com 2019 - 2024. All rights reserved.