Skip to content

Private Key missing in X509Certificate2 after creating certificate #2703

Answered by mregen
ahmadjqureshi asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @ahmadjqureshi, in your case bouncy castle is not used to create a certificate, on .NET Framework 4.8 bc is just used for PEM import/export. Also .NET Framework 4.8 supports the ephemeral keyset. The new certificate has a private key, but it may require a reload to use crypto, but I may not remember correctly.
the PrivateKey property is not used to access the private key. To access the private key you would:

        using (RSA rsaPrivateKey = certificate.GetRSAPrivateKey())
        {
            RSAParameters rsaParams = rsa.ExportParameters(true);
        }

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ahmadjqureshi
Comment options

@mregen
Comment options

mregen Sep 12, 2024
Collaborator

Answer selected by ahmadjqureshi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants