-1
using (ECDsa ecdsa = ECDsa.Create()) // Change curve as needed
{
    // Create a certificate signing request (CSR)
    CertificateRequest csr = new CertificateRequest("cn=MySelfSignedECDSACert", ecdsa, HashAlgorithmName.SHA256);
    // byte[] csrBytes = csr.CreateSigningRequest();
    // Create a self-signed certificate valid for one year
    DateTime notBefore = DateTime.UtcNow;
    DateTime notAfter = notBefore.AddYears(1);
    X509Certificate2 certificate = csr.CreateSelfSigned(notBefore, notAfter);

    byte[] publicKey1 = certificate.GetECDsaPublicKey().ExportSubjectPublicKeyInfo();
    ECDsa privateKey1 = certificate.GetECDsaPrivateKey();
    byte[] pkey = certificate.GetECDsaPrivateKey().ExportECPrivateKey();
    string pgkey = Convert.ToBase64String(pkey);
}

using above code am get public key but not getting private key.

How can i will get private key from above certificate?

bartonjs
  • 30,352
  • 2
  • 71
  • 111

0 Answers0