Search code examples
c#.net.net-corecryptographyprivate-key

Read .der file private key C#


string LoadPrivateKey = "test.der";

X509Certificate2 x509 = new X509Certificate2(LoadPrivateKey, "test");

it is always show "unknown object in factory: DerInteger\r\nParameter name: obj"

I would like to use in the Elliptic Curve Cryptography

how can solve it?

Thank You!


Solution

  • Finally I solved this problem.

    1. Use .pfx include the private key.

    2.

    X509Certificate2 cert = new X509Certificate2("test.pfx", "test");
                    ECDsa mECDsa = cert.GetECDsaPrivateKey();
                    Console.WriteLine("[ECDsa]: "+  mECDsa.KeySize);