OPENSSL-GENPKEY(1SSL)

πŸ’– OPENSSL-GENPKEY πŸ’–

okay bestie, gather round, because openssl-genpkey is literally the main character of key generation, and she lives in section 1SSL of the OpenSSL manual. she does exactly one thing and she does it flawlessly: she generates a private key or a key pair. periodt. πŸ‘‘


✨ NAME ✨

openssl-genpkey β€” generate a private key or key pair. that's it, 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] [-encopt opt:value] [-genparam]
[-text] [-rand files] [-writerand file] [-provider name] [-provider-path
path] [-provparam [name:]key=value] [-propquery propq] [-config
configfile]

copy that exactly fr fr, no cap, every bracket matters πŸ’…


πŸŽ€ DESCRIPTION πŸŽ€

this command generates a private key or key pair. that's the whole plot. iconic behavior, honestly. 🌈


πŸ’… OPTIONS πŸ’…

  • -help β€” prints out a usage message. when you're lost, she's got you. 🫢
  • -out filename β€” write the private key into the file you name. if you don't say anything, standard output gets it instead. πŸ™ˆ
  • -outpubkey filename β€” write the public key into the file you name. if you don't specify this one, no public key gets output at all. like, zero. none. πŸ’€
  • -outform DER|PEM β€” the output format, except when -genparam is given; the default is PEM. see openssl-format-options(1) for the deets.
and when -genparam is given? -outform is just straight-up ignored. she said not today. 😭
  • -verbose β€” outputs "status dots" while generating keys. lil progress crumbs so you know she's cooking. ✨
  • -quiet β€” do not output "status dots" while generating keys. silent, mysterious, ethereal. 🧚
  • -pass arg β€” the output file password source. for everything about the format of arg, go peek at openssl-passphrase-options(1). πŸ”
  • -cipher β€” encrypts the private key with the specified cipher. this option is specified by prepending a hyphen to the cipher name. for example, to encrypt with AES-128 in CBC mode, use -aes-128-cbc. to encrypt with AES-256 in CBC mode, use -aes-256-cbc.
ngl this one trips everybody up: the cipher name is used directly as the option (e.g., -aes-256-cbc), not as an argument to a -cipher flag. so it's not -cipher aes-256-cbc, bestie, it's just the hyphen thing. 🚨

use openssl list -cipher-algorithms to see the available ciphers. slay. πŸ‘‘

  • -algorithm alg β€” the public key algorithm to use, such as RSA, DSA, DH or DHX. if you use this option, it must come before any -pkeyopt options. also, -paramfile and -algorithm are mutually exclusive β€” pick a lane. providers may add algorithms on top of 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.

and a lil note: 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 β€” they're different girlies with different rules. πŸ’œ

  • -pkeyopt opt:value β€” set the public key algorithm option opt to value. the precise set of supported options depends on the public key algorithm used and its implementation. see "KEY GENERATION OPTIONS" and "PARAMETER GENERATION OPTIONS" below for way more detail. 🌸

to list the possible opt values for an algorithm, use:

openssl genpkey -algorithm XXX -help
  • -encopt opt:value β€” set the private key encoder parameter opt to value. wanna set multiple parameters? just pass multiple -encopt options, each one carrying a single parameter. the precise set of supported parameters depends on the public key algorithm involved and its implementation. this is primarily applicable to ML-DSA and ML-KEM, whose private key encoding to a PKCS#8 object can take a number of different forms. the "output_formats" parameter can be used to select the preferred output forms. see EVP_PKEY-ML-DSA(7) and EVP_PKEY-ML-KEM(7) for details. πŸ¦‹
  • -genparam β€” generate a set of parameters instead of a private key. if you use this option, it must precede any -algorithm, -paramfile or -pkeyopt options. order matters, she's strict about it. ⭐
  • -paramfile filename β€” some public key algorithms generate a private key based on a set of parameters, and you can hand those over with this option. if you use it, the public key algorithm used is determined by the parameters. and again: if used, this option must precede any -pkeyopt options. -paramfile and -algorithm are mutually exclusive. 😌
  • -text β€” print an (unencrypted) text representation of private and public keys and parameters, right alongside the PEM or DER structure. like seeing the soul and the fit. πŸ”₯
  • -rand files, -writerand file β€” see "Random State Options" in openssl(1) for details. 🎲
  • -provider name, -provider-path path, -provparam [name:]key=value, -propquery propq β€” see "Provider Options" in openssl(1), provider(7), and property(7). 🫢
  • -config configfile β€” see "Configuration Option" in openssl(1). πŸ“

πŸ”‘ KEY GENERATION OPTIONS πŸ”‘

so here's the tea: the options supported by each algorithm β€” and honestly by each implementation of an algorithm β€” can totally vary. the options for the OpenSSL implementations are detailed below. and heads up: there are no key generation options defined for the X25519, X448, ED25519 or ED448 algorithms. they said "we need nothing, we are enough." πŸ’…


🌟 RSA Key Generation Options 🌟

  • rsa_keygen_bits:numbits β€” the number of bits in the generated key. if you don't specify it, 2048 is used. πŸ“
  • rsa_keygen_primes:numprimes β€” the number of primes in the generated key. if you don't specify it, 2 is used. 2️⃣
  • rsa_keygen_pubexp:value β€” the RSA public exponent value. this can be a large decimal or hexadecimal value if it's preceded by 0x. default value is 65537. πŸ”’

πŸ’œ RSA-PSS Key Generation Options πŸ’œ

note: by default an RSA-PSS key has no parameter restrictions. she's free-spirited like that. πŸ¦‹
  • rsa_keygen_bits:numbits, rsa_keygen_primes:numprimes, rsa_keygen_pubexp:value β€” these options have the exact same meaning as the RSA algorithm. same girls, different era. ✨
  • 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 it's MGF1 parameter. (yes, "it's" β€” we're keeping the original wording exactly, no editing the source bestie πŸ’€)
  • rsa_pss_keygen_saltlen:len β€” if set, the key is restricted and len specifies the minimum salt length. πŸ§‚

🌸 EC Key Generation Options 🌸

the EC key generation options can also be used for parameter generation. multitasking queen. πŸ‘‘

  • ec_paramgen_curve:curve β€” the EC curve to use. OpenSSL supports NIST curve names such as "P-256". 🌈
  • 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. πŸ“

πŸŽ€ 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. ⚠️ and here's the scary part: if other users can see the command-line arguments of the running process, this option may compromise the secret key, so it is best avoided β€” tests-aside. like, please be careful. 😭

see EVP_PKEY-ML-DSA(7) for more detail. πŸ“–


🧚 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. ⚠️ same warning, same energy: 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. πŸ“–


⭐ 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. πŸ—‚οΈ

πŸ’– PARAMETER GENERATION OPTIONS πŸ’–

Okay bestie, here's the tea: every algorithm β€” and even every implementation of an algorithm β€” can have its own lil set of supported options ✨. They are NOT universal. Below are the deets for the OpenSSL implementations, and nothing else, so don't come for me if some third-party provider does its own thing πŸ‘‘


🌸 DSA Parameter Generation Options 🌸

  • dsa_paramgen_bits:numbits β€” how many bits the generated prime gets 🫢. If you don't say anything, it just uses 2048.
  • dsa_paramgen_q_bits:numbits, qbits:numbits β€” the bit count for the q parameter, babes. It must be exactly one of 160, 224, or 256 πŸ’…. Leave it out and it defaults to 224.
  • dsa_paramgen_md:digest, digest:digest β€” the digest used during parameter generation. Gotta be one of sha1, sha224, or sha256, no substitutions πŸ”₯. If you set this, then the bits in q will match the output size of your chosen digest and the dsa_paramgen_q_bits parameter gets straight-up ignored πŸ«₯. If you don't set it, it'll pick a digest whose output matches the number of bits in q β€” so sha1 if q length is 160, sha224 if it's 224, or sha256 if it's 256 ✨.
  • properties:query β€” the digest property query string to use when it's fetching a digest from a provider 🌈.
  • type:type β€” which generation flavor you want. Set it to 1 for legacy FIPS186-2 parameter generation. The default 0 uses FIPS186-4 parameter generation.
  • gindex:index β€” the index for canonical generation and verification of the generator g πŸŽ€. Set it to a positive value in the range 0..255 to use this mode. Larger values will only use the bottom byte, periodt. This index must then be reused during key validation to verify the value of g. If this value isn't set, then g is not verifiable πŸ’€. Default value is -1.
  • hexseed:seed β€” the seed data to use instead of generating a random seed internally 🌱.
Testing purposes ONLY bestie, I mean it πŸ™ˆ. This will either produce fixed values for the generated parameters OR it will fail if the seed didn't generate valid primes. No in-between, no mercy.

πŸ¦‹ DH Parameter Generation Options πŸ¦‹

For most use cases it's recommended to use the group option rather than the type options ✨. Also note: the group option is not used by default if no parameter generation options are specified. Just so you know πŸ‘€.

  • group:name, dh_param:name β€” use a named DH group to select constant values for the DH parameters 🎁. All other options will be ignored if this value is set.

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 β€” if this is set, the appropriate RFC5114 parameters get used instead of generating new ones 🫢. The value 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 will be ignored if this value is set.
  • pbits:numbits, dh_paramgen_prime_len:numbits β€” the number of bits in the prime parameter p πŸ‘‘. Default is 2048.
  • qbits:numbits, dh_paramgen_subprime_len:numbits β€” the number of bits in the sub prime parameter q 🌸. Default is 224. This one's only relevant if you're using it together with the dh_paramgen_type option to generate DHX parameters, iykyk.
  • 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 even be used.
  • type:string β€” the type name of DH parameters you want 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 (yes bestie, that's literally what it says πŸ’€). 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. The OpenSSL default provider uses this 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 β€” sha1 if q length is 160, sha224 if it's 224, or sha256 if it's 256. This one 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 in the range 0..255 to use this mode. Larger values only use the bottom byte. This index must then be reused during key validation to verify the value of g. If not set, then g is not verifiable πŸ’€. Default value is -1. Only used by "fips186_4" and "fips186_2" key generation.
  • hexseed:seed β€” the seed data to use instead of generating a random seed internally 🌱.
Testing purposes ONLY, okay?! πŸ™ˆ This either produces fixed values for the generated parameters OR it fails if the seed didn't generate valid primes. Only used by "fips186_4" and "fips186_2" key generation.

🧚 EC Parameter Generation Options 🧚

The EC parameter generation options are the same as for key generation 🌟. Go peek at "EC Key Generation Options" above, bestie, it's literally all there πŸ‘‘


πŸ’€ NOTES πŸ’€

Using the genpkey program is encouraged over the algorithm-specific utilities, because that way you get access to additional algorithm options AND provider-provided algorithms πŸ”₯. More options, more power, slay.


✨ 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 🌸.

Support for ML-DSA and ML-KEM was added in OpenSSL 3.5 πŸ¦‹.

The -engine option was removed in OpenSSL 4.0 πŸ’€.

The -encopt option was added in OpenSSL 4.0 🌟.

As of OpenSSL 4.0 the -pass and -cipher options apply when private keys are output in either DER or PEM form 🫢. Previously, these private key encryption options were ignored in DER form. Glow-up confirmed πŸ’….


Copyright 2006-2026 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 the whole page bestie, we ate and left no crumbs πŸ“πŸ’– This was OPENSSL-GENPKEY(1SSL) from the 4.0.3 source, dated 2026-09-29 β€” screenshot it, bookmark it, live by it βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from