X509Certificate.CreateFromCertFile - 指定的网络密码不正确 [英] X509Certificate.CreateFromCertFile - the specified network password is not correct
问题描述
我有,我想作为一个客户端用来调用一个SSL SOAP Web服务的.NET应用程序。我一直与 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:\certs\foo。 PFX
I've located the certificate at the following location: C:\certs\foo.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
是应该创建x509证书的一个新实例的静态方法。该方法不重写,并且只有一个参数:路径
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屋!