The **openssl ec** command and utility can be used to process your EC (Elliptic Curve) keys. This article will walk you through examples on processing EC keys with the **openssl ec** utility as well as the **openssl ecparam** utility.

You can submit your CSR with its EC key to The SSL Store for an SSL certificate having an EC key.

An EC private key header and footer is formatted as follows:

```
-----BEGIN EC PRIVATE KEY-----
-----END EC PRIVATE KEY-----
```

This format may be converted to PKCS8 by running the following command with the openssl pkcs8 utility:

`openssl pkcs8 -topk8 -in key.pem -out key-pkcs8.pem`

Where `-topk8`

means to convert to PKCS8, `-in key.pem`

is the EC private key, and `-out key-pkcs8.pem`

will be the file storing the PKCS8 EC private key.

On the other hand, the EC public key header and footer is formatted this way:

```
-----BEGIN PUBLIC KEY-----
-----END PUBLIC KEY-----
```

As you maintain and process different key material you will notice that many of the commands are very much the same or similar in nature.

Private keys should be stored encrypted at rest if at all possible. To encrypt an EC private key, run the following command:

`openssl ec -in key.pem -aes256 -out encrypted-key.pem`

Where `in key.pem`

is the plain text EC private key, `-aes256`

is the symmetric key encryption algorithm to encrypt the private key with, and `-out encrypted-key.pem`

is file storing the encrypted EC private key.

To convert the EC private key from PEM format to DER format, run the following command:

`openssl ec -in key.pem -outform DER -out key.der`

Where `-in key.pem`

is the PEM formatted EC private key, `-outform DER`

is the format to convert to, and `-out key.der`

will be the DER formatted EC private key.

To extract the EC public key from the private key, run the following command:

`openssl ec -in key.pem -pubout -out public-key.pem`

Where `-in key.pem`

is the EC private key, `-pubout`

means extract the public key, and `-out public-key.pem`

is the file storing the EC public key.

## openssl ecparam

### openssl newkey ec

The first openssl ecparam example demonstrates how to generate an EC private key. To create the EC key, run the following command with the openssl ecparam utility:

`openssl ecparam -name prime256v1 -genkey -noout -out key.pem`

Running **openssl ecparam prime256v1** details are as follows: `-name prime256v1`

is the parameter group for sha256, `-genkey`

means to generate an EC private key, `noout -out key.pem`

means to store the generated EC private key in the key.pem file and do not print it out.

You may use the EC public key for encryption and the EC private key for decryption, or digital signatures. The EC private key can be used just the same as any other private key. See our article on openssl dgst for examples on digitally signing messages using the generated EC private key.

EC parameter header and footer is formatted as the following:

```
-----BEGIN EC PARAMETERS-----
-----END EC PARAMETERS-----
```

To print the EC parameters, run the following command:

`openssl ecparam -in ec_param.pem -noout -text`

Where `-in ec_param.pem`

are the EC parameters in PEM format, and `-noout -text`

is text format.

### openssl ecparam -list_curves

The **-list_curves** option to the **openssl ecparam** command will show the available curves.

An example output of **-list_curves** is:

```
secp112r1 : SECG/WTLS curve over a 112 bit prime field
secp112r2 : SECG curve over a 112 bit prime field
secp128r1 : SECG curve over a 128 bit prime field
secp128r2 : SECG curve over a 128 bit prime field
secp160k1 : SECG curve over a 160 bit prime field
secp160r1 : SECG curve over a 160 bit prime field
secp160r2 : SECG/WTLS curve over a 160 bit prime field
secp192k1 : SECG curve over a 192 bit prime field
secp224k1 : SECG curve over a 224 bit prime field
secp224r1 : NIST/SECG curve over a 224 bit prime field
secp256k1 : SECG curve over a 256 bit prime field
secp384r1 : NIST/SECG curve over a 384 bit prime field
secp521r1 : NIST/SECG curve over a 521 bit prime field
prime192v1: NIST/X9.62/SECG curve over a 192 bit prime field
prime192v2: X9.62 curve over a 192 bit prime field
prime192v3: X9.62 curve over a 192 bit prime field
prime239v1: X9.62 curve over a 239 bit prime field
prime239v2: X9.62 curve over a 239 bit prime field
prime239v3: X9.62 curve over a 239 bit prime field
prime256v1: X9.62/SECG curve over a 256 bit prime field
sect113r1 : SECG curve over a 113 bit binary field
sect113r2 : SECG curve over a 113 bit binary field
sect131r1 : SECG/WTLS curve over a 131 bit binary field
sect131r2 : SECG curve over a 131 bit binary field
sect163k1 : NIST/SECG/WTLS curve over a 163 bit binary field
sect163r1 : SECG curve over a 163 bit binary field
sect163r2 : NIST/SECG curve over a 163 bit binary field
sect193r1 : SECG curve over a 193 bit binary field
sect193r2 : SECG curve over a 193 bit binary field
sect233k1 : NIST/SECG/WTLS curve over a 233 bit binary field
sect233r1 : NIST/SECG/WTLS curve over a 233 bit binary field
sect239k1 : SECG curve over a 239 bit binary field
sect283k1 : NIST/SECG curve over a 283 bit binary field
sect283r1 : NIST/SECG curve over a 283 bit binary field
sect409k1 : NIST/SECG curve over a 409 bit binary field
sect409r1 : NIST/SECG curve over a 409 bit binary field
sect571k1 : NIST/SECG curve over a 571 bit binary field
sect571r1 : NIST/SECG curve over a 571 bit binary field
c2pnb163v1: X9.62 curve over a 163 bit binary field
c2pnb163v2: X9.62 curve over a 163 bit binary field
c2pnb163v3: X9.62 curve over a 163 bit binary field
c2pnb176v1: X9.62 curve over a 176 bit binary field
c2tnb191v1: X9.62 curve over a 191 bit binary field
c2tnb191v2: X9.62 curve over a 191 bit binary field
c2tnb191v3: X9.62 curve over a 191 bit binary field
c2pnb208w1: X9.62 curve over a 208 bit binary field
c2tnb239v1: X9.62 curve over a 239 bit binary field
c2tnb239v2: X9.62 curve over a 239 bit binary field
c2tnb239v3: X9.62 curve over a 239 bit binary field
c2pnb272w1: X9.62 curve over a 272 bit binary field
c2pnb304w1: X9.62 curve over a 304 bit binary field
c2tnb359v1: X9.62 curve over a 359 bit binary field
c2pnb368w1: X9.62 curve over a 368 bit binary field
c2tnb431r1: X9.62 curve over a 431 bit binary field
wap-wsg-idm-ecid-wtls1: WTLS curve over a 113 bit binary field
wap-wsg-idm-ecid-wtls3: NIST/SECG/WTLS curve over a 163 bit binary field
wap-wsg-idm-ecid-wtls4: SECG curve over a 113 bit binary field
wap-wsg-idm-ecid-wtls5: X9.62 curve over a 163 bit binary field
wap-wsg-idm-ecid-wtls6: SECG/WTLS curve over a 112 bit prime field
wap-wsg-idm-ecid-wtls7: SECG/WTLS curve over a 160 bit prime field
wap-wsg-idm-ecid-wtls8: WTLS curve over a 112 bit prime field
wap-wsg-idm-ecid-wtls9: WTLS curve over a 160 bit prime field
wap-wsg-idm-ecid-wtls10: NIST/SECG/WTLS curve over a 233 bit binary field
wap-wsg-idm-ecid-wtls11: NIST/SECG/WTLS curve over a 233 bit binary field
wap-wsg-idm-ecid-wtls12: WTLS curve over a 224 bit prime field
Oakley-EC2N-3:
IPSec/IKE/Oakley curve #3 over a 155 bit binary field.
Not suitable for ECDSA.
Questionable extension field!
Oakley-EC2N-4:
IPSec/IKE/Oakley curve #4 over a 185 bit binary field.
Not suitable for ECDSA.
Questionable extension field!
brainpoolP160r1: RFC 5639 curve over a 160 bit prime field
brainpoolP160t1: RFC 5639 curve over a 160 bit prime field
brainpoolP192r1: RFC 5639 curve over a 192 bit prime field
brainpoolP192t1: RFC 5639 curve over a 192 bit prime field
brainpoolP224r1: RFC 5639 curve over a 224 bit prime field
brainpoolP224t1: RFC 5639 curve over a 224 bit prime field
brainpoolP256r1: RFC 5639 curve over a 256 bit prime field
brainpoolP256t1: RFC 5639 curve over a 256 bit prime field
brainpoolP320r1: RFC 5639 curve over a 320 bit prime field
brainpoolP320t1: RFC 5639 curve over a 320 bit prime field
brainpoolP384r1: RFC 5639 curve over a 384 bit prime field
brainpoolP384t1: RFC 5639 curve over a 384 bit prime field
brainpoolP512r1: RFC 5639 curve over a 512 bit prime field
brainpoolP512t1: RFC 5639 curve over a 512 bit prime field
SM2 : SM2 curve over a 256 bit prime field
```

## Conclusion

This article has attempted to detail how to create and process EC keys with the **openssl ec** and **openssl ecparam** commands.

## Leave a Reply