I wrote following code to extract ECDH public key blob:
var curve = ECCurve.NamedCurves.nistP256;
ECDiffieHellman ecdh = ECDiffieHellman.Create(curve);
var bytes = ecdh.PublicKey.ToByteArray();
Console.WriteLine($"Public Key (byte length with format info): {bytes.Length}");
var hexString = BitConverter.ToString(bytes).Replace("-", string.Empty);
Console.WriteLine($"Public Key (hex with format info): {hexString}");
I got following output:
Public Key (byte length with format info): 72
Public Key (hex with format info): 45434B3120000000C3F1AC1F3D272BE14A26BE35B1A31F6C969425259162C06BEBE6AE977809984FC509ED5154E1E4782079D4BDDCDA6E083E48D271755267AD765CAD0E66B9FD9F
The first 4 bytes (key type) are 45434B31 (in hex format). This appears to be in big endian format where as this MSDN link indicates that it should be in little endian format, which dictates that these 4 bytes should be 314B4345 (again, as shown in this link). The link also uses "magic", instead of "key type". The next 4 bytes are 20000000 (in hex format) appears to be in the little endian format (as the above link says).
Is there a logical explanation for why key type is formatted as big endian? Or am I missing something here?