openssl pkey -in key.pem -pubout -out pub.pemcat pub.pem # -----BEGIN PUBLIC KEY-----openssl pkey -pubin -in pub.pem -text -noout# shows the uncompressed point (04‖x‖y) and the curve: prime256v1openssl x509 -in cert.pem -pubkey -noout > pub.pem # from a certificateopenssl ec -in legacy.pem -pubout -out pub.pem # legacy tool, same outputHow it works
pkeyis the format-agnostic key tool in OpenSSL 3.x — it reads PKCS#8 and SEC1 private keys without extra flags.-puboutswitches the output from private to public; the result is always the SPKIBEGIN PUBLIC KEYcontainer.- Reading a public key back requires
-pubin— without it,pkeyassumes the input is private and fails.
Gotchas
- Forgetting
-pubinwhen inspecting a public key givesCould not read private key— misleading wording for "you gave me a public key without saying so". - There is no way to go from public back to private — if
-puboutis your backup strategy, you have backed up the wrong half. - An encrypted private key prompts for the passphrase even for
-pubout(the public half lives inside the encrypted structure) — automation needs-passinor an unencrypted working copy.