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


- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01