0

I'm making private/public key using ecdh

var ecdh = new ECDiffieHellmanCng(CngKey.Create(CngAlgorithm.ECDiffieHellmanP256, null, new CngKeyCreationParameters { ExportPolicy = CngExportPolicies.AllowPlaintextExport }));
var privateKey = ecdh.Key.Export(CngKeyBlobFormat.EccPrivateBlob);
var publickey = ecdh.Key.Export(CngKeyBlobFormat.EccPublicBlob);

This code works fine, but I want to use Algorithm prime256v1 and CngAlgorithm has no such option. How can I do that ?

Nino
  • 6,931
  • 2
  • 27
  • 42
David
  • 4,332
  • 13
  • 54
  • 93
  • Aren't you using this already? From the [CngAlgorithm.ECDiffieHellmanP256](https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.cngalgorithm.ecdiffiehellmanp256?view=netframework-4.8) description: `An object that specifies an ECDH algorithm that uses the P-256 curve.` – Panagiotis Kanavos Oct 17 '19 at 11:10
  • Check [this question](https://crypto.stackexchange.com/questions/52883/ec-curve-selection) in crypto.stackexchange.com. It explains what this name means and where it came from. – Panagiotis Kanavos Oct 17 '19 at 11:13
  • So P256 = Prime256v1 ? – David Oct 17 '19 at 11:15
  • 1
    That's what the question and the linked source says - looks like bankers didn't want to use the same names as programmers so they defined their own curve IDs – Panagiotis Kanavos Oct 17 '19 at 11:26
  • thnank for the answer! :) Then I have to delete this question I guess :) – David Oct 17 '19 at 11:35
  • No, better leave it because other people will probably have the same question – Panagiotis Kanavos Oct 17 '19 at 11:35

1 Answers1

1

According to the docs, CngAlgorithm.ECDiffieHellmanP256 specifies the P-256 curve :

An object that specifies an ECDH algorithm that uses the P-256 curve.

This answer in crypto.stackexchange.com explains what those names come from different sources and that P-256 in NIST notation corresponds to prime256v1 in "ANSI X9.62 : Public Key Cryptography For The Financial Services Industry".

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236