Skip to content

Getting ECDiffieHellman private key from a certificate in Windows certificate store #1537

@MikeRosoft

Description

@MikeRosoft

We use elliptic curve certificate for key derivation and encryption:

  • A uses B's elliptic curve public key + ephemeral private key to derive an AES symmetric key.
  • A encrypts data with the AES key.
  • A sends encrypted data and ephemeral public key to B.
  • B uses private key + ephemeral public key to derive the same AES key.
  • B decrypts the data.

But we now have a problem: how to get the private ECDiffieHellman key from the certificate in Windows store? For public key, we use the following code (see https://stackoverflow.com/questions/47116611 ):

//Extension method; there is no extension method to directly get ECDiffieHellman public/private key from certificate
using (ECDsa ecdsa = certificate.GetECDsaPublicKey()) 
{
    return ECDiffieHellman.Create(ecdsa.ExportParameters(false));
}

But we can't do the same with private key, because private key is normally not exportable for certificates in certificate store. (Mathematically, there is no difference between an ECDsa and ECDiffieHellman key).


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pri2Indicates issues/PRs that are medium priorityarea-System.SecurityIssues related to security practices for .NET developers.dotnet-api/prod

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions