加载X509Certificate结果exceptionCryptographicException“找不到原始签名者”

我试图实例化一个X509Certificate对象,但我继续遇到相同的CryptographicException ,并显示错误消息:

“找不到原始签名者”。

我尝试了几种加载证书的方法:

 // some different things that I have tried var cert = X509Certificate.CreateFromCertFile(certFileName); var cert2 = new X509Certificate(byteArray); var cert3 = new X509Certificate(byteArray, secretString); var cert4 = X509Certificate.CreateFromSignedFile(certFileName); 

我已尝试从文件和字节数组加载。 每次我得到同样的错误。 可能是什么导致了这个?

我解决了这个问题。 我试图只加载证书文件,该文件不包含私钥。 要解决此问题,我必须在购买证书的计算机上安装私钥,然后将其导出为.pfx文件并将其移至我实际想要使用它的位置。 我确定是一个新手的错误。 希望我的愚蠢问题将在未来帮助其他新手。

  var collection = new X509Certificate2Collection(); collection.Import(byteArray); return collection; 

通过https://stackoverflow.com/a/44073265,https://stackoverflow.com/users/6535399 ,为msft写密码 – 例如https://github.com/dotnet/corefx/pull/25920