OPENSSL-GENPKEY(1ossl)

๐Ÿ“ฆ
version 15.1 ยท 2 versions
, in freebsd 15.1

๐Ÿ’– openssl-genpkey(1ossl) ๐Ÿ’–

๐ŸŒธ NAME ๐ŸŒธ

okay so bestie, openssl-genpkey โ€” from the 1ossl manual โ€” is literally the command that generates a private key or key pair. Thatโ€™s the whole vibe. ๐Ÿ’…


โœจ SYNOPSIS โœจ

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]

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

This command generates a private key or key pair. no cap, thatโ€™s the main character job. ๐Ÿ‘‘


๐ŸŽ€ OPTIONS ๐ŸŽ€

  • -help โ€” prints out a usage message. helpful icon behavior. โœจ
  • -out filename โ€” outputs the private key to the specified file. If this argument is not specified, then standard output is used. ๐Ÿซถ
  • -outpubkey filename โ€” outputs the public key to the specified file. If this argument is not specified, then the public key is not output. ๐Ÿ™ˆ
  • -outform DER|PEM โ€” 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 โ€” outputs โ€œstatus dotsโ€ while generating keys. dot dot dot slay. ๐Ÿ”ฅ
  • -quiet โ€” does not output โ€œstatus dotsโ€ while generating keys. stealth mode. ๐Ÿคซ
  • -pass arg โ€” the output file password source. For more information about the format of arg, see openssl-passphrase-options(1). ๐Ÿ”
  • -cipher โ€” this option encrypts the private key with the supplied cipher. Any algorithm name accepted by EVP_get_cipherbyname() is acceptable, such as des3. cipher girlie mode. ๐Ÿ’…
  • -algorithm alg โ€” 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 options are not shared between DH and DHX keys. ๐Ÿซ 

  • -pkeyopt opt:value โ€” sets 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 โ€” generates a set of parameters instead of a private key. If used, this option must precede any -algorithm, -paramfile or -pkeyopt options. parameter arc, not key arc. ๐ŸŒˆ
  • -paramfile filename โ€” 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 โ€” prints an (unencrypted) text representation of private and public keys and parameters along with the PEM or DER structure. read her like a book. ๐Ÿ“–
  • -rand files, -writerand file โ€” see โ€œRandom State Optionsโ€ in openssl(1) for details. randomness is the moment. โญ
  • -engine id โ€” see โ€œEngine Optionsโ€ in openssl(1). This option is deprecated.
๐Ÿšจ bestie, -engine is deprecated. Itโ€™s giving legacy energy. Still documented, but yeah, deprecated.
  • -provider name โ€” see โ€œProvider Optionsโ€ in openssl(1), provider(7), and property(7). provider bestie behavior. ๐Ÿฆ‹
  • -provider-path path โ€” same reference as above: see โ€œProvider Optionsโ€ in openssl(1), provider(7), and property(7). path girlie. ๐ŸŒธ
  • -provparam [name:]key=value โ€” same reference again: see โ€œProvider Optionsโ€ in openssl(1), provider(7), and property(7). key=value realness. ๐Ÿ’œ
  • -propquery propq โ€” same reference, one more time: see โ€œProvider Optionsโ€ in openssl(1), provider(7), and property(7). query vibes. ๐ŸŽ€
  • -config configfile โ€” see โ€œConfiguration Optionโ€ in openssl(1). config slay. โœจ

๐Ÿ”‘ KEY GENERATION OPTIONS ๐Ÿ”‘

The options supported by each algorithm โ€” and indeed each implementation of an algorithm โ€” can vary. The options for the OpenSSL implementations are detailed below. There are no key generation options defined for the X25519, X448, ED25519 or ED448 algorithms. ๐Ÿ’…

๐Ÿงฎ RSA Key Generation Options

  • rsa_keygen_bits:numbits โ€” the number of bits in the generated key. If not specified, 2048 is used. thicc key energy. ๐Ÿ”ฅ
  • rsa_keygen_primes:numprimes โ€” the number of primes in the generated key. If not specified, 2 is used. prime time. โญ
  • rsa_keygen_pubexp:value โ€” the RSA public exponent value. This can be a large decimal or hexadecimal value if preceded by 0x. Default value is 65537. iconic default. ๐Ÿ‘‘

๐Ÿงธ RSA-PSS Key Generation Options

Note: by default an RSA-PSS key has no parameter restrictions. free spirit. ๐Ÿฆ‹

  • rsa_keygen_bits:numbits, rsa_keygen_primes:numprimes, rsa_keygen_pubexp:value โ€” these options have the same meaning as the RSA algorithm. same lore, different key type. ๐Ÿซถ
  • rsa_pss_keygen_md:digest โ€” if set, the key is restricted and can only use digest for signing. locked in. ๐Ÿ”
  • rsa_pss_keygen_mgf1_md:digest โ€” if set, the key is restricted and can only use digest as its MGF1 parameter. MGF1 but make it restrictive. ๐Ÿ’…
  • rsa_pss_keygen_saltlen:len โ€” if set, the key is restricted and len specifies the minimum salt length. minimum salt, maximum drama. ๐Ÿง‚

๐ŸŒฟ EC Key Generation Options

The EC key generation options can also be used for parameter generation. multitasking icon. โœจ

  • ec_paramgen_curve:curve โ€” the EC curve to use. OpenSSL supports NIST curve names such as "P-256". curve selection is a vibe check. ๐ŸŒธ
  • ec_param_enc:encoding โ€” the encoding to use for parameters. The encoding parameter must be either named_curve or explicit. The default value is named_curve. explicit only if you mean it. ๐Ÿ’€

๐Ÿงฌ ML-DSA Key Generation Options

  • hexseed:seed โ€” this specifies the optional ML-DSA seed in hexadecimal form. The seed is 32 bytes, giving 64 hexadecimal digits. When generated from an explicit seed, the key is completely determined by the seed value. If other users can see the command-line arguments of the running process, this option may compromise the secret key; it is best avoided, tests-aside.

See EVP_PKEY-ML-DSA(7) for more detail. ๐Ÿงš

๐Ÿšจ secret key safety check: visible command-line args + explicit seed = potential compromise. not the moment, bestie. ๐Ÿ™ˆ

๐ŸŒˆ ML-KEM Key Generation Options

  • hexseed:seed โ€” this specifies the optional ML-KEM seed in hexadecimal form. The seed is 64 bytes, giving 128 hexadecimal digits. When generated from an explicit seed, the key is completely determined by the seed value. If other users can see the command-line arguments of the running process, this option may compromise the secret key; it is best avoided, tests-aside.

See EVP_PKEY-ML-KEM(7) for more detail. ๐Ÿ’œ

๐Ÿšจ same warning, same energy: if other users can see the running processโ€™s command-line arguments, this option may compromise the secret key. best avoided, tests-aside. ๐Ÿ’€

๐ŸŒŠ DH Key Generation Options

  • group:name โ€” the paramfile option is not required if a named group is used here. See the โ€œDH Parameter Generation Optionsโ€ section below. named group? we love a shortcut. ๐Ÿซถ

โœจ PARAMETER GENERATION OPTIONS โœจ

Okay so real talk: every algorithm โ€” and honestly every implementation of every algorithm โ€” gets to pick and choose which options it supports. It's giving "choose your own adventure" but cryptography. The options for the OpenSSL implementations are all listed below, bestie, so buckle up ๐ŸŽ€


๐ŸŒธ DSA Parameter Generation Options ๐ŸŒธ

  • dsa_paramgen_bits:numbits โ€” how many bits the generated prime gets. Don't specify it and you get 2048. Default city ๐Ÿ’…
  • dsa_paramgen_q_bits:numbits, qbits:numbits โ€” how many bits the q parameter gets. Has to be one of 160, 224 or 256. No specifying = 224.
  • dsa_paramgen_md:digest, digest:digest โ€” the digest used during parameter generation. Must be one of sha1, sha224 or sha256. Set this and the number of bits in q will match the output size of whatever digest you picked, and the dsa_paramgen_q_bits parameter gets straight-up ignored (rude but fair ๐Ÿ™ˆ). Don't set it and OpenSSL picks a digest whose output matches the bits in q โ€” so sha1 if q length is 160, sha224 if it's 224, sha256 if it's 256.
  • properties:query โ€” the digest property query string used when fetching a digest from a provider. It's giving "which provider are we shopping at" ๐Ÿ›๏ธ
  • type:type โ€” what flavour of generation to use. Set it to 1 for legacy FIPS186-2 parameter generation. The default of 0 uses FIPS186-4 parameter generation. Choose wisely โœจ
  • gindex:index โ€” the index for canonical generation and verification of the generator g. Set it to a positive value ranging from 0..255 to use this mode. Larger values will only use the bottom byte (iconic little quirk). This index must then be reused during key validation to verify the value of g. Not set = g is not verifiable. Default value is -1.
  • hexseed:seed โ€” the seed seed data to use instead of generating a random seed internally. โš ๏ธ This should be used for testing purposes only, fr fr โ€” it will either produce fixed values for the generated parameters OR it will fail if the seed didn't generate valid primes. No in-between.

๐Ÿฆ‹ DH Parameter Generation Options ๐Ÿฆ‹

Okay so for most use cases it's recommended you use the group option instead of the type options. And heads up: the group option is not used by default if you don't specify any parameter generation options at all. Noted ๐Ÿ“

  • group:name, dh_param:name โ€” use a named DH group to select constant values for the DH parameters. All other options get ignored if this value is set (it's the main character, obviously ๐Ÿ‘‘).

Valid values associated with the algorithm of "DH" are: "ffdhe2048", "ffdhe3072", "ffdhe4096", "ffdhe6144", "ffdhe8192", "modp_1536", "modp_2048", "modp_3072", "modp_4096", "modp_6144", "modp_8192".

Valid values associated with the algorithm of "DHX" are the RFC5114 names "dh_1024_160", "dh_2048_224", "dh_2048_256".

  • dh_rfc5114:num โ€” set this and the appropriate RFC5114 parameters get used instead of generating new ones. num can be 1, 2 or 3, which are equivalent to using the group option with one of "dh_1024_160", "dh_2048_224" or "dh_2048_256". All other options get ignored if this value is set.
  • pbits:numbits, dh_paramgen_prime_len:numbits โ€” number of bits in the prime parameter p. Default is 2048.
  • qbits:numbits, dh_paramgen_subprime_len:numbits โ€” number of bits in the sub prime parameter q. Default is 224. Only relevant if used together with the dh_paramgen_type option to generate DHX parameters.
  • safeprime-generator:value, dh_paramgen_generator:value โ€” the value to use for the generator g. Default is 2. The algorithm option must be "DH" for this parameter to be used.
  • type:string โ€” the type name of DH parameters to generate. Valid values are:

๐Ÿ’œ "generator"

Use a safe prime generator with the option safeprime_generator. The algorithm option must be "DH".

๐Ÿ’œ "fips186_4"

FIPS186-4 parameter generation. The algorithm option must be "DHX".

๐Ÿ’œ "fips186_2"

FIPS186-4 parameter generation. The algorithm option must be "DHX".

๐Ÿ’œ "group"

Can be used with the option pbits to select one of "ffdhe2048", "ffdhe3072", "ffdhe4096", "ffdhe6144" or "ffdhe8192". The algorithm option must be "DH".

๐Ÿ’œ "default"

Selects a default type based on the algorithm. This is what the OpenSSL default provider uses to set the type for backwards compatibility. If algorithm is "DH" then "generator" is used. If algorithm is "DHX" then "fips186_2" is used.

  • dh_paramgen_type:value โ€” the type of DH parameters to generate. Valid values are 0, 1, 2 or 3, which correspond to setting the option type to "generator", "fips186_2", "fips186_4" or "group".
  • digest:digest โ€” the digest to use during parameter generation. Must be one of sha1, sha224 or sha256. If set, the number of bits in qbits will match the output size of the specified digest and the qbits parameter gets ignored. If not set, a digest is used that gives an output matching the number of bits in q, i.e. sha1 if q length is 160, sha224 if it's 224 or sha256 if it's 256. This is only used by "fips186_4" and "fips186_2" key generation.
  • properties:query โ€” the digest property query string to use when fetching a digest from a provider. Only used by "fips186_4" and "fips186_2" key generation.
  • gindex:index โ€” the index for canonical generation and verification of the generator g. Set it to a positive value ranging from 0..255 to use this mode. Larger values will only use the bottom byte. This index must then be reused during key validation to verify the value of g. Not set = g is not verifiable. Default value is -1. Only used by "fips186_4" and "fips186_2" key generation.
  • hexseed:seed โ€” the seed seed data to use instead of generating a random seed internally. โš ๏ธ Testing purposes only, bestie. It will either produce fixed values for the generated parameters OR it will fail if the seed didn't generate valid primes. Only used by "fips186_4" and "fips186_2" key generation.

๐Ÿงš EC Parameter Generation Options ๐Ÿงš

Plot twist: these are literally the same as for key generation. Go peek at EC Key Generation Options above, iykyk ๐Ÿ’–


โญ NOTES โญ

The use of the genpkey program is encouraged over the algorithm specific utilities, because you get additional algorithm options and ENGINE provided algorithms can be used. So likeโ€ฆ genpkey is the moment. Periodt. ๐Ÿ‘‘


๐ŸŒˆ 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 ๐Ÿ•ฐ๏ธ

A lil timeline of glow-ups, bestie:

  • 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.

Copyright 2006-2025 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


And that's a wrap, bestie! ๐Ÿซถ This whole page is from OpenSSL 3.5.6, dated 2026-04-07 โ€” so go forth, generate those keys, and remember: genpkey ate and left no crumbs. ๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from