I'm just starting out with rust and playing with a toy encryption library following docs at https://docs.rs/openssl/0.10.28/openssl/. I'd like to generate an elliptic-curve private+public keypair and print them in der or pem formats. I found it pretty straightforward to do with the private key
use openssl::ec::{EcKey,EcGroup};
use openssl::nid::Nid;
pub fn generate_keypair() {
let group = EcGroup::from_curve_name(Nid::SECP256K1).unwrap();
let key = EcKey::generate(&group).unwrap();
println!("{:?}", key.private_key_to_der().unwrap()); // can use pem instead and print as utf8-string
}
However there doesn't seem to be any method like public_key_to_der
for EcKey
to export a public key, even debug-printing it doesn't work:
let public = key.public_key();
println!("{:?}", public);
gives a compilation error
openssl::ec::EcPointRef` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`