$manlookup

openssl-genpkey

(1ssl)

generate a private key or key pair

User commands20 optionsopenssl 3.5.6-1~deb13u2
openssl genpkey [-help] [-out filename] [-outpubkey filename] [-outform DER|PEM] [-verbose] [-quiet] [-pass arg] [-cipher] [-paramfile file] [-algorithm alg] [-pkeyopt opt:value] [-genparam] [-text] [-rand files] [-writerand file] [-engine id] [-provider name] [-provider-path path] [-provparam [name:]key=value] [-propquery propq] [-config configfile]

Options

20
-help

Print out a usage message.

-outfilename

Output the private key to the specified file. If this argument is not specified then standard output is used.

-outpubkeyfilename

Output the public key to the specified file. If this argument is not specified then the public key is not output.

-outform

The output format, except when -genparam is given; the default is PEM. See openssl-format-options(1) for details. When -genparam is given, -outform is ignored.

-verbose

Output "status dots" while generating keys.

-quiet

Do not output "status dots" while generating keys.

-passarg

The output file password source. For more information about the format of arg see openssl-passphrase-options(1).

-ciphercipher

This option encrypts the private key with the supplied cipher. Any algorithm name accepted by EVP_get_cipherbyname() is acceptable such as des3.

-algorithmalg

Public key algorithm to use such as RSA, DSA, DH or DHX. If used this option must precede any -pkeyopt options. The options -paramfile and -algorithm are mutually exclusive. Engines or providers may add algorithms in addition to the standard built-in ones. Valid built-in algorithm names for private key generation are RSA, RSA-PSS, EC, X25519, X448, ED25519, ED448, ML-DSA and ML-KEM. Valid built-in algorithm names for parameter generation (see the -genparam option) are DH, DSA and EC. Note that the algorithm name X9.42 DH may be used as a synonym for DHX keys and PKCS#3 refers to DH Keys. Some

-pkeyoptopt

Set the public key algorithm option opt to value. The precise set of options supported depends on the public key algorithm used and its implementation. See "KEY GENERATION OPTIONS" and "PARAMETER GENERATION OPTIONS" below for more details. To list the possible opt values for an algorithm use: openssl genpkey -algorithm XXX -help

-genparam

Generate a set of parameters instead of a private key. If used this option must precede any -algorithm, -paramfile or -pkeyopt options.

-paramfilefilename

Some public key algorithms generate a private key based on a set of parameters. They can be supplied using this option. If this option is used the public key algorithm used is determined by the parameters. If used this option must precede any -pkeyopt options. The options -paramfile and -algorithm are mutually exclusive.

-text

Print an (unencrypted) text representation of private and public keys and parameters along with the PEM or DER structure.

-rand-writerandfiles

See "Random State Options" in openssl(1) for details.

-engineid

See "Engine Options" in openssl(1). This option is deprecated.

-providername

-provider-pathpath

-provparam[name:]key=value

-propquerypropq

See "Provider Options" in openssl(1), provider(7), and property(7).

-configconfigfile

See "Configuration Option" in openssl(1).

DESCRIPTION

This command generates a private key or key pair.

NOTES

The use of the genpkey program is encouraged over the algorithm specific utilities because additional algorithm options and ENGINE provided algorithms can be used.

EXAMPLES

Generate an RSA private key using default parameters:

 openssl genpkey -algorithm RSA -out key.pem

Encrypt output private key using 128 bit AES and the passphrase "hello":

 openssl genpkey -algorithm RSA -out key.pem -aes-128-cbc -pass pass:hello

Generate a 2048 bit RSA key using 3 as the public exponent:

 openssl genpkey -algorithm RSA -out key.pem \
     -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:3

Generate 2048 bit DSA parameters that can be validated: The output values for gindex and seed are required for key validation purposes and are not saved to the output pem file).

 openssl genpkey -genparam -algorithm DSA -out dsap.pem -pkeyopt pbits:2048 \
     -pkeyopt qbits:224 -pkeyopt digest:SHA256 -pkeyopt gindex:1 -text

Generate DSA key from parameters:

 openssl genpkey -paramfile dsap.pem -out dsakey.pem

Generate 4096 bit DH Key using safe prime group ffdhe4096:

 openssl genpkey -algorithm DH -out dhkey.pem -pkeyopt group:ffdhe4096

Generate 2048 bit X9.42 DH key with 256 bit subgroup using RFC5114 group3:

 openssl genpkey -algorithm DHX -out dhkey.pem -pkeyopt dh_rfc5114:3

Generate a DH key using a DH parameters file:

 openssl genpkey -paramfile dhp.pem -out dhkey.pem

Output DH parameters for safe prime group ffdhe2048:

 openssl genpkey -genparam -algorithm DH -out dhp.pem -pkeyopt group:ffdhe2048

Output 2048 bit X9.42 DH parameters with 224 bit subgroup using RFC5114 group2:

 openssl genpkey -genparam -algorithm DHX -out dhp.pem -pkeyopt dh_rfc5114:2

Output 2048 bit X9.42 DH parameters with 224 bit subgroup using FIP186-4 keygen:

 openssl genpkey -genparam -algorithm DHX -out dhp.pem -text \
     -pkeyopt pbits:2048 -pkeyopt qbits:224 -pkeyopt digest:SHA256 \
     -pkeyopt gindex:1 -pkeyopt dh_paramgen_type:2

Output 1024 bit X9.42 DH parameters with 160 bit subgroup using FIP186-2 keygen:

 openssl genpkey -genparam -algorithm DHX -out dhp.pem -text \
     -pkeyopt pbits:1024 -pkeyopt qbits:160 -pkeyopt digest:SHA1 \
     -pkeyopt gindex:1 -pkeyopt dh_paramgen_type:1

Output 2048 bit DH parameters:

 openssl genpkey -genparam -algorithm DH -out dhp.pem \
     -pkeyopt dh_paramgen_prime_len:2048

Output 2048 bit DH parameters using a generator:

 openssl genpkey -genparam -algorithm DH -out dhpx.pem \
     -pkeyopt dh_paramgen_prime_len:2048 \
     -pkeyopt dh_paramgen_type:1

Generate EC parameters:

 openssl genpkey -genparam -algorithm EC -out ecp.pem \
        -pkeyopt ec_paramgen_curve:secp384r1 \
        -pkeyopt ec_param_enc:named_curve

Generate EC key from parameters:

 openssl genpkey -paramfile ecp.pem -out eckey.pem

Generate EC key directly:

 openssl genpkey -algorithm EC -out eckey.pem \
        -pkeyopt ec_paramgen_curve:P-384 \
        -pkeyopt ec_param_enc:named_curve

Generate an X25519 private key:

 openssl genpkey -algorithm X25519 -out xkey.pem

Generate an ED448 private key:

 openssl genpkey -algorithm ED448 -out xkey.pem

Generate an ML-DSA-65 private key:

 openssl genpkey -algorithm ML-DSA-65 -out ml-dsa-key.pem

Generate an ML-KEM-768 private key:

 openssl genpkey -algorithm ML-KEM-768 -out ml-kem-key.pem

HISTORY

The ability to use NIST curve names, and to generate an EC key directly, were added in OpenSSL 1.0.2. The ability to generate X25519 keys was added in OpenSSL 1.1.0. The ability to generate X448, ED25519 and ED448 keys was added in OpenSSL 1.1.1.

The -engine option was deprecated in OpenSSL 3.0.

Support for ML-DSA and ML-KEM was added in OpenSSL 3.5.