【问题标题】:"Object contains only the public half of a key pair. A private key must also be provided." Using 2 .pem's & X509 & MS Services3.Security“对象仅包含密钥对的公共部分。还必须提供私钥。”使用 2 .pem's & X509 & MS Services3.Security
【发布时间】:2011-05-19 14:40:12
【问题描述】:

代码如下:

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】:

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

    http://www.openssl.org/

    mutualCert 是用于连接 ADP 的 SSL 证书 signCert 用于您的 SOAP/Web 服务调用

    几个月来我一直在研究 ADP 接口,但我仍然遇到问题。

    希望这会有所帮助 -道格

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      • 2018-07-19
      • 2019-04-08
      • 1970-01-01
      • 2013-08-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多