X509Certificate.CreateFromCertFile - 指定的网络密码不正确

X509Certificate.CreateFromCertFile - the specified network password is not correct(X509Certificate.CreateFromCertFile - 指定的网络密码不正确)
本文介绍了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 - 指定的网络密码不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)