相关疑难解决方法(0)

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

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

我在以下位置找到了证书: C:\certs\foo.pfx

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

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;
     }
}
Run Code Online (Sandbox Code Playgroud)

听起来像尝试读取磁盘的.NET应用程序是个例外.该方法CreateFromCertFile是一个静态方法,应该创建X509Certificate的新实例.该方法未被重写,并且只有一个参数:路径.

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

_COMPlusExceptionCode = -532459699
Source=mscorlib
Run Code Online (Sandbox Code Playgroud)

问题:有没有人知道异常的原因"指定的网络密码不正确"?

c# ssl-certificate x509certificate

24
推荐指数
4
解决办法
5万
查看次数

ASP.NET - 指定的网络密码不正确

我在我的开发机器上有一个需要证书的WCF客户端,它工作正常.
部署到生产服务器后,我收到以下错误:

[CryptographicException: The specified network password is not correct.]
Run Code Online (Sandbox Code Playgroud)

DEV - Win7 32BIT IIS 7.5
生产 - Win SERVER 64BIT 2008 IIS 7.5

即使网络之间没有密码也没有证书密码.(我知道因为开发工作没有密码).我唯一的密码是WCF,它与DEV相同.

CrmServiceClient crm = new CrmServiceClient("CrmServiceEndpoint");
crm.ClientCredentials.UserName.UserName = CrmConfigRepository.CrmUserName;//fine
crm.ClientCredentials.UserName.Password = CrmConfigRepository.CrmPassword;//fine
crm.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(Path);
///THIS WONT WORK AS WELL
crm.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(Path, "", X509KeyStorageFlags.Exportable); 
Run Code Online (Sandbox Code Playgroud)

这是完整的堆栈

[CryptographicException: The specified network password is not correct. ]
   System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) +41
   System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromFile(String fileName, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx) +0
   System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags …
Run Code Online (Sandbox Code Playgroud)

.net c# certificate

19
推荐指数
3
解决办法
3万
查看次数

标签 统计

c# ×2

.net ×1

certificate ×1

ssl-certificate ×1

x509certificate ×1