OPENSSL-GENPKEY(1ossl)
๐ 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-genparamis given; the default isPEM. Seeopenssl-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, seeopenssl-passphrase-options(1). ๐-cipherโ this option encrypts the private key with the supplied cipher. Any algorithm name accepted byEVP_get_cipherbyname()is acceptable, such asdes3. cipher girlie mode. ๐-algorithm algโ public key algorithm to use, such asRSA,DSA,DHorDHX. If used, this option must precede any-pkeyoptoptions. The options-paramfileand-algorithmare 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,-paramfileor-pkeyoptoptions. 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-pkeyoptoptions. The options-paramfileand-algorithmare mutually exclusive. ๐ง-textโ prints an (unencrypted) text representation of private and public keys and parameters along with thePEMorDERstructure. read her like a book. ๐-rand files,-writerand fileโ see โRandom State Optionsโ inopenssl(1)for details. randomness is the moment. โญ-engine idโ see โEngine Optionsโ inopenssl(1). This option is deprecated.
๐จ bestie, -engine is deprecated. Itโs giving legacy energy. Still documented, but yeah, deprecated.
-provider nameโ see โProvider Optionsโ inopenssl(1),provider(7), andproperty(7). provider bestie behavior. ๐ฆ-provider-path pathโ same reference as above: see โProvider Optionsโ inopenssl(1),provider(7), andproperty(7). path girlie. ๐ธ-provparam [name:]key=valueโ same reference again: see โProvider Optionsโ inopenssl(1),provider(7), andproperty(7). key=value realness. ๐-propquery propqโ same reference, one more time: see โProvider Optionsโ inopenssl(1),provider(7), andproperty(7). query vibes. ๐-config configfileโ see โConfiguration Optionโ inopenssl(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,2048is used. thicc key energy. ๐ฅrsa_keygen_primes:numprimesโ the number of primes in the generated key. If not specified,2is used. prime time. โญrsa_keygen_pubexp:valueโ the RSA public exponent value. This can be a large decimal or hexadecimal value if preceded by0x. Default value is65537. 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 theRSAalgorithm. 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 eithernamed_curveorexplicit. The default value isnamed_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โ theparamfileoption 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 get2048. Default city ๐dsa_paramgen_q_bits:numbits,qbits:numbitsโ how many bits theqparameter gets. Has to be one of160,224or256. No specifying =224.dsa_paramgen_md:digest,digest:digestโ the digest used during parameter generation. Must be one ofsha1,sha224orsha256. Set this and the number of bits inqwill match the output size of whatever digest you picked, and thedsa_paramgen_q_bitsparameter gets straight-up ignored (rude but fair ๐). Don't set it and OpenSSL picks a digest whose output matches the bits inqโ sosha1ifqlength is160,sha224if it's224,sha256if it's256.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 to1for legacy FIPS186-2 parameter generation. The default of0uses FIPS186-4 parameter generation. Choose wisely โจgindex:indexโ the index for canonical generation and verification of the generatorg. Set it to a positive value ranging from0..255to 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 ofg. Not set =gis not verifiable. Default value is-1.hexseed:seedโ the seedseeddata 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.numcan be1,2or3, which are equivalent to using thegroupoption 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 parameterp. Default is2048.qbits:numbits,dh_paramgen_subprime_len:numbitsโ number of bits in the sub prime parameterq. Default is224. Only relevant if used together with thedh_paramgen_typeoption to generate DHX parameters.safeprime-generator:value,dh_paramgen_generator:valueโ the value to use for the generatorg. Default is2. 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 are0,1,2or3, which correspond to setting the optiontypeto"generator","fips186_2","fips186_4"or"group".digest:digestโ the digest to use during parameter generation. Must be one ofsha1,sha224orsha256. If set, the number of bits inqbitswill match the output size of the specified digest and theqbitsparameter gets ignored. If not set, a digest is used that gives an output matching the number of bits inq, i.e.sha1ifqlength is160,sha224if it's224orsha256if it's256. 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 generatorg. Set it to a positive value ranging from0..255to use this mode. Larger values will only use the bottom byte. This index must then be reused during key validation to verify the value ofg. Not set =gis not verifiable. Default value is-1. Only used by"fips186_4"and"fips186_2"key generation.hexseed:seedโ the seedseeddata 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
-engineoption was deprecated in OpenSSL 3.0. ๐ - Support for ML-DSA and ML-KEM was added in OpenSSL 3.5.
๐ COPYRIGHT ๐
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
- freebsd 15.1: base 15.1
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms