“对象仅包含密钥对的公共部分。还必须提供私钥。”使用 2 个 .pem ' X509& MS服务3.安全

发布于 2024-11-08 14:47:51 字数 1387 浏览 3 评论 0原文

代码如下:

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 是我的私有证书,但我真的不确定。我从某种(网络服务)食谱中获取了代码......网络服务说他们不查看密码。

错误信息是:

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

Here's the code:

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);

I think that mutualCert, auth, is my public cert and signCert, SOAP, is my private cert, but I'm really not sure. I took the code from a sort of (web service) cookbook... The web service says that they don't look at the passwords.

The error message is:

"Object contains only the public half of a key pair. A private key must also be provided."

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

度的依靠╰つ 2024-11-15 14:47:51

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

http://www.openssl.org/

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

我已经在 ADP 接口上工作了几个月,但仍然遇到问题。

希望这有帮助
-道格

You need to convert the .pem file to a .pfx for the .Net framework to be able to use it. The .pfx will contain both the public and private keys. You can use OpenSSL to convert the .pem file that ADP sent you to a .pfx file.

http://www.openssl.org/

mutualCert is the SSL certificate for connecting to ADP
signCert is used for your SOAP/webservice calls

I've been working on an inerface with ADP for several months and I'm still having problems.

Hope this helps
-Doug

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文