Convert, Check and Export EC Keys with OpenSSL
You will finish with a repeatable way to inspect an elliptic-curve (EC) key, check that it is internally consistent, export its public half, and convert between PEM and DER without overwriting the source. The examples use the local openssl ec command. The installed executable reports OpenSSL 3.6.1, while the packaged local manpage identifies the interface as OpenSSL 3.0.13, so check the output on the machine where you will run a production command.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about fifteen minutes. You need OpenSSL and either an existing EC private key or permission to create a temporary test key. The normal commands are unprivileged. Do not use sudo to handle a key unless its directory genuinely requires elevated access; changing ownership or permissions to work around a wrong path can expose private material.
1. Confirm the command and protect the input
Check which executable your shell will run, then read its option summary:
$ command -v openssl
/home/linuxbrew/.linuxbrew/bin/openssl
$ openssl version
OpenSSL 3.6.1 27 Jan 2026
$ openssl ec -help
The EC subcommand reads a private key by default and writes a private key by default. Its output format defaults to PEM. The input and output paths must be different. This matters even when you are only changing an encoding: a failed conversion should not destroy the only copy.
If you need a harmless test input, create it in a directory with restrictive permissions. This command uses the separate ecparam subcommand to create a prime256v1 test key:
$ umask 077
$ mkdir -p ./openssl-ec-test
$ openssl ecparam -name prime256v1 -genkey -noout -out ./openssl-ec-test/key.pem
For a real key, replace ./openssl-ec-test/key.pem below with its exact path. Keep private keys out of shared directories and shell history. Do not paste their contents into a ticket or terminal transcript.
Checkpoint
You know the executable, have a readable private key, and have chosen a new output path for every transformation.
2. Check the key before using it
Use -check to ask OpenSSL to check the consistency of a private or public EC key. Add -noout so the encoded key is not printed:
$ openssl ec -in ./openssl-ec-test/key.pem -check -noout
EC Key valid.
A successful command prints a validity message and exits successfully. This is a structural consistency check. It does not prove that the key is approved for a particular certificate, application, curve policy or trust relationship.
If the input is encrypted, OpenSSL prompts for its pass phrase. For automation, -passin accepts a password source described by OpenSSL's passphrase options. Prefer a protected file descriptor or file managed by your secret-handling system. Avoid putting a literal secret in the command line, because other users or monitoring tools may be able to see process arguments.
3. Inspect the components without emitting a reusable key
Use -text for a human-readable view and keep -noout enabled:
$ openssl ec -in ./openssl-ec-test/key.pem -text -noout
Private-Key: (256 bit)
priv:
...
pub:
...
ASN1 OID: prime256v1
The exact hexadecimal values and line wrapping vary. This output includes the private scalar, so treat it as secret. Do not redirect it to a shared log, paste it into a bug report, or leave it in a shell scrollback that others can read. If you only need a machine-readable conversion, omit -text instead of printing a diagnostic dump.
When you want to print the curve parameters rather than the normal encoded key, add -param_out. That is still disclosure of key-related material and is not a substitute for a policy review. Use it only where the receiving tool needs those parameters.
4. Export the public key
Derive a standalone public-key file with -pubout. The input remains private, while the new file is a SubjectPublicKeyInfo public-key structure:
$ openssl ec \
-in ./openssl-ec-test/key.pem \
-pubout \
-out ./openssl-ec-test/public.pem
$ sed -n '1p' ./openssl-ec-test/public.pem
-----BEGIN PUBLIC KEY-----
The public file is safe to distribute where the protocol expects a public key, but it is not proof that the corresponding private key is authentic or belongs to a particular person or service. Keep the private file protected. If your input is already a public key, add -pubin; openssl ec otherwise assumes a private-key input.
Checkpoint
Run the following before handing the result to another system:
$ test -s ./openssl-ec-test/public.pem && echo 'public key written'
public key written
5. Convert PEM to DER safely
PEM is text with a header and footer. DER is a binary encoding. Specify the new format and a different destination:
$ openssl ec \
-in ./openssl-ec-test/key.pem \
-outform DER \
-out ./openssl-ec-test/key.der
$ file ./openssl-ec-test/key.der
./openssl-ec-test/key.der: data
When reading DER, select it explicitly with -inform DER:
$ openssl ec \
-inform DER \
-in ./openssl-ec-test/key.der \
-check -noout
EC Key valid.
The output format option controls the encoded key, not the key's curve or cryptographic strength. Do not infer format from a file name. If a receiving application expects a public key, add -pubout as a separate output operation rather than renaming a private-key file.
6. Change encryption or EC encodings deliberately
With PEM output, -des3 encrypts a private-key output and prompts for a new pass phrase:
$ openssl ec \
-in ./openssl-ec-test/key.pem \
-des3 \
-out ./openssl-ec-test/key-encrypted.pem
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
Do not use this example in unattended automation until you have selected a safe -passout source. Conversely, running the command with no encryption option can remove the pass phrase from an encrypted input, so treat that as a security-sensitive change. OpenSSL's current provider model and build may not offer every legacy cipher, and the manpage limits these encryption options to PEM output. Use PKCS#8 with openssl pkcs8 when that is the format your application requires; openssl ec is not the PKCS#8 conversion command.
-param_enc named_curve is the default and records the curve by identifier. -param_enc explicit writes the parameters explicitly. -conv_form compressed, uncompressed (the default), or hybrid controls point encoding. These are interoperability choices, not general-purpose ways to make a key stronger. Test the exact receiving library before replacing a key used by a service.
There is no undo command for overwriting a key. Keep the original until the new file has passed the recipient's import and verification checks. If an output attempt failed, remove only the incomplete new file after checking its path, then rerun with a fresh destination. Do not delete the source as part of a chained command.
Done means
openssl versionandopenssl ec -helpwere checked on the target machine.-check -nooutreports that the input EC key is valid.- Human-readable output containing private values was kept out of shared logs.
- A public key was exported with
-puboutwhen one was required. - PEM and DER paths were kept separate, with
-informand-outformstated explicitly when needed. - Any encryption, parameter encoding or point conversion change was tested with the receiving application before deployment.