0
CngKey key = CngKey.Create(CngAlgorithm.ECDiffieHellmanP521, null,
   new CngKeyCreationParameters { ExportPolicy = CngExportPolicies.AllowPlaintextExport });    
byte[] keyBlob= key.Export(CngKeyBlobFormat.EccPrivateBlob);

the length of keyBlob is 206. what is its format? which bytes are the 32 bytes private key and 64 bytes public key?

at Import a Public key from somewhere else to CngKey?, the length is 4+4+64+32=104.

  • It is a byte[]. A key takes a string input and creates a class object. The string initialize the class (like a seed to a random number generators). The key strength from NSA is listed at following : https://en.wikipedia.org/wiki/Key_size – jdweng Oct 15 '19 at 15:02
  • i mean the CngKey Blob Format. which bytes are the 32 bytes private key in the 206 bytes. – user12220851 Oct 15 '19 at 15:38
  • As I said the string is a seed into a pseudo random generator whose output are the 32 byte array. It is not reversible. – jdweng Oct 15 '19 at 16:01

1 Answers1

0

The binary structure of the blobs is the same for all three curves:

<magic number, 4 bytes><modulus length in bytes, 4 bytes><x-value of public key><y-value of public key><private key>

In detail applies:

  • secp256r1 / NIST P-256

    Private: 45434B32 20000000 <x-value of public key, 32 bytes><y-value of public key, 32 bytes><private key, 32 bytes>   total length: 104 bytes
    Public:  45434B31 20000000 <x-value of public key, 32 bytes><y-value of public key, 32 bytes>                          total length:  72 bytes
    
  • secp384r1 / NIST P-384

    Private: 45434B34 30000000 <x-value of public key, 48 bytes><y-value of public key, 48 bytes><private key, 48 bytes>   total length: 152 bytes
    Public:  45434B33 30000000 <x-value of public key, 48 bytes><y-value of public key, 48 bytes>                          total length: 104 bytes
    
  • secp521r1 / NIST P-521

    Private: 45434B36 42000000 <x-value of public key, 66 bytes><y-value of public key, 66 bytes><private key, 66 bytes>   total length: 206 bytes
    Public:  45434B35 42000000 <x-value of public key, 66 bytes><y-value of public key, 66 bytes>                          total length: 140 bytes
    

The private key and the x- and y-component of the public key are stored in big-endian format. All three components have the length of the modulus. The different lengths of the blobs are thus caused by the different modulus of the curves.

See also: SECG, SEC2, key blob format, magic numbers, format of ECCPublicBlob and ECCPrivateBlob

Topaco
  • 40,594
  • 4
  • 35
  • 62
  • thank you very much! would you please help me with another question? https://stackoverflow.com/questions/58414020/how-to-use-bitcoin-pub-private-key-to-do-ecdh – user12220851 Oct 16 '19 at 13:58