X509Certificate.CreateFromCertFile

编程入门 行业动态 更新时间:2024-10-16 00:19:02
本文介绍了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

本文发布于:2023-11-15 15:52:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1595826.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:X509Certificate   CreateFromCertFile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!