I'm trying to do an ECDH key exchange using C# BouncyCastle. I have been successful in creating the necessary AsymmetricCipherKeyPair objects and I'm also able to generate the shared key of the other partys public key.
However, to actually exchange the public key, I need it as a byte[] or at least anything I can turn into raw data, since the protocol I'm using to transport the keys between the parties wont take any BouncyCastle object.
X9ECParameters ecPars = NistNamedCurves.GetByName("P-521");
ECDomainParameters ecDomPars = new ECDomainParameters(ecPars.Curve, ecPars.G, ecPars.N, ecPars.H, ecPars.GetSeed());
IAsymmetricCipherKeyPairGenerator gen = GeneratorUtilities.GetKeyPairGenerator("ECDH");
gen.Init(new ECKeyGenerationParameters(ecDomPars, new SecureRandom()));
AsymmetricCipherKeyPair keyPair = gen.GenerateKeyPair();
IBasicAgreement keyAgreement = AgreementUtilities.GetBasicAgreement("ECDH");
keyAgreement.Init(keyPair.Private);
So what I'm needing here is the key value of keyPair.Public as a byte[].
I hope you understand where I'm heading and can help me.