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-genparamis given; the default isPEM. seeopenssl-format-options(1)for the deets.
and when-genparamis given?-outformis 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 atopenssl-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-cipherflag. 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 asRSA,DSA,DHorDHX. if you use this option, it must come before any-pkeyoptoptions. also,-paramfileand-algorithmare 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-encoptoptions, 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 toML-DSAandML-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. seeEVP_PKEY-ML-DSA(7)andEVP_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,-paramfileor-pkeyoptoptions. 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-pkeyoptoptions.-paramfileand-algorithmare 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" inopenssl(1)for details. π²-provider name,-provider-path path,-provparam [name:]key=value,-propquery propqβ see "Provider Options" inopenssl(1),provider(7), andproperty(7). π«Ά-config configfileβ see "Configuration Option" inopenssl(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,2048is used. πrsa_keygen_primes:numprimesβ the number of primes in the generated key. if you don't specify it,2is used. 2οΈβ£rsa_keygen_pubexp:valueβ the RSA public exponent value. this can be a large decimal or hexadecimal value if it's preceded by0x. default value is65537. π’
π 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 eithernamed_curveorexplicit. the default value isnamed_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 uses2048.dsa_paramgen_q_bits:numbits,qbits:numbitsβ the bit count for theqparameter, babes. It must be exactly one of160,224, or256π . Leave it out and it defaults to224.dsa_paramgen_md:digest,digest:digestβ the digest used during parameter generation. Gotta be one ofsha1,sha224, orsha256, no substitutions π₯. If you set this, then the bits inqwill match the output size of your chosen digest and thedsa_paramgen_q_bitsparameter gets straight-up ignored π«₯. If you don't set it, it'll pick a digest whose output matches the number of bits inqβ sosha1ifqlength is160,sha224if it's224, orsha256if it's256β¨.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 to1for legacy FIPS186-2 parameter generation. The default0uses FIPS186-4 parameter generation.gindex:indexβ the index for canonical generation and verification of the generatorgπ. Set it to a positive value in the range0..255to 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 ofg. If this value isn't set, thengis 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 be1,2or3, which are equivalent to using thegroupoption 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 parameterpπ. Default is2048.qbits:numbits,dh_paramgen_subprime_len:numbitsβ the number of bits in the sub prime parameterqπΈ. Default is224. This one's only relevant if you're using it together with thedh_paramgen_typeoption to generate DHX parameters, iykyk.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 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 optionsafeprime_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 optionpbitsto 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 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βsha1ifqlength is160,sha224if it's224, orsha256if it's256. 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 generatorgπ. Set it to a positive value in the range0..255to use this mode. Larger values only use the bottom byte. This index must then be reused during key validation to verify the value ofg. If not set, thengis 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 π
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
- ubuntu stonking: openssl 4.0.3-1ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms