I have following code:
ECDiffieHellman ecdh = ECDiffieHellman.Create(ECCurve.NamedCurves.nistP256);
ECDiffieHellmanPublicKey ecdhPublic = ecdh.PublicKey;
How can I export the ECDiffieHellmanPublicKey instance (ecdhPublic) into DER encoded file?
I have following code:
ECDiffieHellman ecdh = ECDiffieHellman.Create(ECCurve.NamedCurves.nistP256);
ECDiffieHellmanPublicKey ecdhPublic = ecdh.PublicKey;
How can I export the ECDiffieHellmanPublicKey instance (ecdhPublic) into DER encoded file?
Using BouncyCastle (http://www.bouncycastle.org/) you can export your ECDH public key to a DER encoded ANS.1 Object
X9ECParameters ecP = NistNamedCurves.GetByName("P-256");
ECDomainParameters ecSpec = new ECDomainParameters(ecP.Curve, ecP.G, ecP.N, ecP.H, ecP.GetSeed());
ECKeyPairGenerator g = new ECKeyPairGenerator();
g.Init(new ECKeyGenerationParameters(ecSpec, new SecureRandom()));
AsymmetricCipherKeyPair server = g.GenerateKeyPair();
ECPublicKeyParameters serverPub = (ECPublicKeyParameters)server.Public;
var result = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(serverPub).GetDerEncoded();