Reputation: 157
I am implementing a key exchange mechanism between my client and a server. The client is written in C# and server is on Java.
On the client I use the following code to generate my public key
aliceKey = CngKey.Create(CngAlgorithm.ECDiffieHellmanP521);
alicePubKeyBlob = aliceKey.Export(CngKeyBlobFormat.EccPublicBlob);
The size of alicePubKeyBlob
is 140 bytes.
On the server side however the key size if 66 bytes for the P-521curve
(uses bouncy castle)
If I try to import the server key in the client , I get an exception with the message "Parameter is incorrect"
Is there something that I am missing out?
Upvotes: 1
Views: 1262
Reputation: 157
I figured out the issue.
Reference: http://msdn.microsoft.com/en-us/library/windows/desktop/aa375520(v=vs.85).aspx
The 140 byte is due to the following formatof public key. 4 bytes: Magic number for ECDHPublicP521 = 0x354B4345 4 bytes: for X and Y length = 42 00 00 00 ( 42 = 66 byte length) The next 66 bytes is the X the next 66 bytes is the Y.
The server generates the X & Y of 66 bytes each. Ensure to add a padding of 0x00 for both X &Y if the length is less than 66 bytes.
Upvotes: 1