简体   繁体   中英

Public Key blob length using Elliptic curve cryptography (P521 curve) in c#

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM