X509Certificate.CreateFromCertFile - 指定的网络密码不正确 [英] X509Certificate.CreateFromCertFile - the specified network password is not correct

查看:30
本文介绍了X509Certificate.CreateFromCertFile - 指定的网络密码不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .NET 应用程序,我想将其用作客户端来调用 SSL SOAP Web 服务.我已获得名为 foo.pfx 的有效客户端证书.证书本身有密码.

I have a .NET application that I want to use as a client to call an SSL SOAP web service. I have been supplied with a valid client certificate called foo.pfx. There is a password on the certificate itself.

我在以下位置找到了证书:C:certsfoo.pfx

I've located the certificate at the following location: C:certsfoo.pfx

要调用 Web 服务,我需要附加客户端证书.代码如下:

To call the web service, I need to attach the client certificate. Here's the code:

public X509Certificate GetCertificateFromDisk(){
    try{             

       string certPath = ConfigurationManager.AppSettings["MyCertPath"].ToString(); 
       //this evaluates to "c:\certs\foo.pfx". So far so good.

       X509Certificate myCert = X509Certificate.CreateFromCertFile(certPath);
       // exception is raised here! "The specified network password is not correct" 

       return cert;

     }
    catch (Exception ex){    
        throw;
     }
}

听起来异常是在尝试读取磁盘的 .NET 应用程序周围.CreateFromCertFile 方法是一个静态方法,它应该创建一个新的 X509Certificate 实例.该方法没有被覆盖,并且只有一个参数:路径.

It sounds like the exception is around the .NET application trying to read the disk. The method CreateFromCertFile is a static method that should create a new instance of X509Certificate. The method isn't overridden, and has only one argument: the path.

当我检查异常时,我发现:

When I inspect the Exception, I find this:

_COMPlusExceptionCode = -532459699
Source=mscorlib

问题:有谁知道指定的网络密码不正确"异常的原因是什么?

Question: does anyone know what the cause of the exception "The specified network password is not correct" ?

推荐答案

原来我试图从 .pfx 而不是 .cer 文件创建证书.

Turns out that I was trying to create a certificate from the .pfx instead of the .cer file.

经验教训...

  • .cer 文件是二进制形式的 X.509 证书.它们是DER 编码.
  • .pfx 文件是容器文件.也是DER编码的.它们不仅包含证书,还包含加密形式的私钥.
  • .cer files are an X.509 certificate in binary form. They are DER encoded.
  • .pfx files are container files. Also DER encoded. They contain not only certificates, but also private keys in encrypted form.

这篇关于X509Certificate.CreateFromCertFile - 指定的网络密码不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆