I try to figure out how ECDiffieHellman is working under .Net.
I wonder, why there are two implementations of ECDiffieHellman which seems to be very simliar.
The Cng
stands for Cryptography Next Generation (CNG), it should be the better one, or not?
Why this dualism? Which one to use?
System.Security.Cryptography.ECDiffieHellman.Create()
var alice = ECDiffieHellman.Create();
var bob = ECDiffieHellman.Create();
Assert.That(alice.PublicKey.ToXmlString(),
Is.Not.EqualTo(bob.PublicKey.ToXmlString()));
var aliceSharedSecret = alice.DeriveKeyMaterial(bob.PublicKey);
var bobSharedSecret = bob.DeriveKeyMaterial(alice.PublicKey);
Assert.That(aliceSharedSecret, Is.EqualTo(bobSharedSecret));
new System.Security.Cryptography.ECDiffieHellmanCng()
var alice = new ECDiffieHellmanCng();
var bob = new ECDiffieHellmanCng();
Assert.That(alice.PublicKey.ToXmlString(),
Is.Not.EqualTo(bob.PublicKey.ToXmlString()));
var aliceSharedSecret = alice.DeriveKeyMaterial(bob.PublicKey);
var bobSharedSecret = bob.DeriveKeyMaterial(alice.PublicKey);
Assert.That(aliceSharedSecret, Is.EqualTo(bobSharedSecret));