How do I serialize and deserialize the public key for ECDiffieHellmanOpenSsl on Linux?

#1

I’m trying to port my key exchange setup to dotnet core (preview 3.0) with Linux support. For Linux support it seems I need to be using the ECDiffieHellmanOpenSsl class available in System.Security.Cryptography.OpenSsl on Nuget. I can’t figure out how to serialize and deserialize the public key to communicate between the server and client.

Using the equivalent CNG class (ECDiffieHellmanCng) you would simply call

ecdh.PublicKey.ToByteArray()

to serialize the key into a byte array, then once the key has been sent to the other party, that party would import it using

EncKeyBlob = ecdh.DeriveKeyMaterial(CngKey.Import(otherpublickey, CngKeyBlobFormat.EccPublicBlob));

However, calling ecdh.PublicKey.ToByteArray() on ECDiffieHellmanOpenSsl throws Unhandled Exception: System.PlatformNotSupportedException: Operation is not supported on this platform. on Ubuntu 18.04.

Additionally, I cannot see any CngKey.Import() equivalent for the OpenSSL version of the class.

What am I missing here?

.NET Foundation Website | Blog | Projects | Code of Conduct