Hello, I'm playing with BouncyCastle in Java and C# and noticed that exporting a ECC key to the PEM format produces different results. For instance, in Java I would get something similar to
-----BEGIN PUBLIC KEY----- MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEPAn00hp37lJQvFuKqfpPx9ai3CyFMSPJ FkPcVoCS7qCZnr4DLsmZ+O/DYvhdEg6XA/JxPfy2TKCJXFW2O/t4Zg== -----END PUBLIC KEY----- which matches what one would get with `openssl ec -in priv.pem -pubout -out pub.pem`. In C# the result is similar to -----BEGIN PUBLIC KEY----- MIIBMzCB7AYHKoZIzj0CATCB4AIBATAsBgcqhkjOPQEBAiEA//////////////// /////////////////////v///C8wRAQgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAEIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHBEEEeb5m fvncu6xVoGKVzocLBwKb/NstzijZWfKBWxb4F5hIOtp3JqPEZV2k+/wOEQio/Re0 SKaFVBmcR9CP+xDUuAIhAP////////////////////66rtzmr0igO7/SXozQNkFB AgEBA0IABNl2l5hlF403Rl/lRsZPmdkMkJ2zyBLqXeWBEhfUvmHTCN5jcckjIZy5 dVi7WHdYrA9+yCf7+hYNmear04caCc0= -----END PUBLIC KEY----- Is there a way to export ECC keys in C# using BouncyCastle so they include only the bare minimum required parameters for re-importing at a later time? In case it helps, here's part of the code used for this: // Generate a keypair. var eckeygen = new ECKeyGenerationParameters (spec, securerng); var keygen = new ECKeyPairGenerator (); keygen.Init (eckeygen); var kp = keygen.GenerateKeyPair (); // Export public key to PEM var textWriter = new StringWriter (); var pemWriter = new PemWriter (textWriter); pemWriter.WriteObject (kp.Public); pemWriter.Writer.Flush (); string pemkey = textWriter.ToString (); One difference between the Java code and the C# one is that in the former I'm using JcaPEMWriter, which doesn't seem to be available in C#. Thanks, -- -- Guilherme Polo