Loading X509Certificate results in exception CryptographicException “Cannot find the original signer”

核能气质少年 提交于 2019-12-30 05:54:38

问题


I am trying to instantiate an X509Certificate object, but I keep running into the same CryptographicException, with the error message:

"Cannot find the original signer".

I have tried several ways of loading the certificate:

// 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);

I have tried both loading from a file and from a byte array. Each time I get the same error. What could be causing this?


回答1:


I figured out the problem. I was attempting to load just the certificate file, which did not include the private key. To fix the problem, I had to install the private key on the machine on which the certificate was purchased, and then export it as a .pfx file and move it to where I actually wanted to use it. I'm sure was a newbie mistake. Hopefully, my silly issue will help other newbies in the future.




回答2:


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

via https://stackoverflow.com/a/44073265, by https://stackoverflow.com/users/6535399, who writes crypto for msft - e.g. https://github.com/dotnet/corefx/pull/25920



来源:https://stackoverflow.com/questions/19190404/loading-x509certificate-results-in-exception-cryptographicexception-cannot-find

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!