I'm trying to refactor some client-side code from BouncyCastle to Microsoft Cng. I've figured out how to convert key format(ECC key blobs) between them, but I couldn't calculate the same secret.
Currently, the client uses
Org.BouncyCastle.Crypto.Agreement.ECDHBasicAgreement.CalculateAgreement() to calculate the shared secret. The length of the shared secret depends on the curve(e.g, length of shared secrets for
SecP224k1 is 28 bytes).
System.Security.Cryptography.ECDiffieHellman) provides several methods:
DeriveKeyFromHash. However, none of them returns a result of 28 bytes. DeriveKeyFromHash returns bytes of 16/20/32/48/64 depends on HashAlgorithm, and DeriveKeyMaterial returns the same 32 bytes as DeriveKeyFromHash(SHA256).
Edit: Microsoft Cng's DeriveKey returns Hashed secret.
How to calculate the same secret using Microsoft Cng?