简体   繁体   中英

Unable to Instantiate X509Certificate2 from Byte Array

I am trying to use a self-signed certificate to configure IdentityServer3, I used openssl to create a x509 certificate as follows: openssl req -x509 -sha256 -days 365 -key key.pem -in csr.csr -out certificate.pem then merged the key and cert using : pkcs12 -export -in my-cert.pem inkey my-key.pem -out xyz-cert.pfx i then converted the content of xyz-cert.pfx to Base64String which is stored in a key in web.config, then tried to use the certificate to instantiate X509Certificate2 as follows:

var certificate = Convert.FromBase64String(ConfigurationManager.AppSettings["SigningCertificate"]);

        var options = new IdentityServerOptions
        {
            SigningCertificate = new X509Certificate2(certificate, ConfigurationManager.AppSettings["SigningCertificatePassword"]),
            RequireSsl = false, // DO NOT DO THIS IN 
            Factory = factory
        };

the following exception is then thrown: 在此处输入图片说明

I can't figure out where i got it wrong. Thanks for your help

var options = new IdentityServerOptions
{
    string CertText = ConfigurationManager.AppSettings["SigningCertificatePassword"];
    byte[] certBytes = Convert.FromBase64String(certText);
    SigningCertificate = new X509Certificate2(certificate, certBytes),
    RequireSsl = false, // DO NOT DO THIS IN 
    Factory = factory
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM