“对象仅包含密钥对的公共部分。还必须提供私钥。”使用 2 个 .pem ' X509& MS服务3.安全
代码如下:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将 .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