I am working with (EC)DHE encryption type x25519 and I have a big problem on calculating shared key.
I have three key:
Alice’s private key:
a : "984a382e1e48d2a522a0e81b92fd13517e904316c6687a59d66cd2e5d9519a53"
Alice’s public key:
Q(a) = a*G(a) : "3db045ba8a16efd9e15de287158097ee754ce5d76e83c5e434109dd132a4736d"
Bob’s public key:
Q(b) = b*G(b) : "74676252b0757ba3cb945ea053d9d65897a22e01592f7fa9c9503b818cd9df5a"
So now I need to combine Alice’s private key and Bob’s public key like this (to find a shared key between them):
Z = a * Q(b) = a * b * G(b)
Do anyone help me with this problem using C#? (I need a programming code).
Microsoft has no default implementation of the elliptic curve x25519. However their implementations of cryptographic Diffie Hellman objects allows us to define our own curve.
Once we define our own curve to use (x25519) we can use Microsoft's
ECDiffieHellmanCng
implementation to import the curve, generate keys, and create shared secrets.Thanks to Yasar_yy for his question about an unrelated topic on x25519 he implemented the curve for us.
We implement a curve using the
ECCurve
classAfter we define the curve we want to use we just need to generate the keys for the curve and the rest is standard for using the
ECDiffieHellmanCng
class.To use this very basic class we just call
GenerateKeys
and subsequentlyCreateSharedSecret
.