1GENPKEY(1) OpenSSL GENPKEY(1)
2
3
4
6 openssl-genpkey, genpkey - generate a private key
7
9 openssl genpkey [-help] [-out filename] [-outform PEM|DER] [-pass arg]
10 [-cipher] [-engine id] [-paramfile file] [-algorithm alg] [-pkeyopt
11 opt:value] [-genparam] [-text]
12
14 The genpkey command generates a private key.
15
17 -help
18 Print out a usage message.
19
20 -out filename
21 Output the key to the specified file. If this argument is not
22 specified then standard output is used.
23
24 -outform DER|PEM
25 This specifies the output format DER or PEM. The default format is
26 PEM.
27
28 -pass arg
29 The output file password source. For more information about the
30 format of arg see "Pass Phrase Options" in openssl(1).
31
32 -cipher
33 This option encrypts the private key with the supplied cipher. Any
34 algorithm name accepted by EVP_get_cipherbyname() is acceptable
35 such as des3.
36
37 -engine id
38 Specifying an engine (by its unique id string) will cause genpkey
39 to attempt to obtain a functional reference to the specified
40 engine, thus initialising it if needed. The engine will then be set
41 as the default for all available algorithms. If used this option
42 should precede all other options.
43
44 -algorithm alg
45 Public key algorithm to use such as RSA, DSA or DH. If used this
46 option must precede any -pkeyopt options. The options -paramfile
47 and -algorithm are mutually exclusive. Engines may add algorithms
48 in addition to the standard built-in ones.
49
50 Valid built-in algorithm names for private key generation are RSA,
51 RSA-PSS, EC, X25519, X448, ED25519 and ED448.
52
53 Valid built-in algorithm names for parameter generation (see the
54 -genparam option) are DH, DSA and EC.
55
56 Note that the algorithm name X9.42 DH may be used as a synonym for
57 the DH algorithm. These are identical and do not indicate the type
58 of parameters that will be generated. Use the dh_paramgen_type
59 option to indicate whether PKCS#3 or X9.42 DH parameters are
60 required. See "DH Parameter Generation Options" below for more
61 details.
62
63 -pkeyopt opt:value
64 Set the public key algorithm option opt to value. The precise set
65 of options supported depends on the public key algorithm used and
66 its implementation. See "KEY GENERATION OPTIONS" and "PARAMETER
67 GENERATION OPTIONS" below for more details.
68
69 -genparam
70 Generate a set of parameters instead of a private key. If used this
71 option must precede any -algorithm, -paramfile or -pkeyopt options.
72
73 -paramfile filename
74 Some public key algorithms generate a private key based on a set of
75 parameters. They can be supplied using this option. If this option
76 is used the public key algorithm used is determined by the
77 parameters. If used this option must precede any -pkeyopt options.
78 The options -paramfile and -algorithm are mutually exclusive.
79
80 -text
81 Print an (unencrypted) text representation of private and public
82 keys and parameters along with the PEM or DER structure.
83
85 The options supported by each algorithm and indeed each implementation
86 of an algorithm can vary. The options for the OpenSSL implementations
87 are detailed below. There are no key generation options defined for the
88 X25519, X448, ED25519 or ED448 algorithms.
89
90 RSA Key Generation Options
91 rsa_keygen_bits:numbits
92 The number of bits in the generated key. If not specified 2048 is
93 used.
94
95 rsa_keygen_primes:numprimes
96 The number of primes in the generated key. If not specified 2 is
97 used.
98
99 rsa_keygen_pubexp:value
100 The RSA public exponent value. This can be a large decimal or
101 hexadecimal value if preceded by 0x. Default value is 65537.
102
103 RSA-PSS Key Generation Options
104 Note: by default an RSA-PSS key has no parameter restrictions.
105
106 rsa_keygen_bits:numbits, rsa_keygen_primes:numprimes,
107 rsa_keygen_pubexp:value
108 These options have the same meaning as the RSA algorithm.
109
110 rsa_pss_keygen_md:digest
111 If set the key is restricted and can only use digest for signing.
112
113 rsa_pss_keygen_mgf1_md:digest
114 If set the key is restricted and can only use digest as it's MGF1
115 parameter.
116
117 rsa_pss_keygen_saltlen:len
118 If set the key is restricted and len specifies the minimum salt
119 length.
120
121 EC Key Generation Options
122 The EC key generation options can also be used for parameter
123 generation.
124
125 ec_paramgen_curve:curve
126 The EC curve to use. OpenSSL supports NIST curve names such as
127 "P-256".
128
129 ec_param_enc:encoding
130 The encoding to use for parameters. The "encoding" parameter must
131 be either "named_curve" or "explicit". The default value is
132 "named_curve".
133
135 The options supported by each algorithm and indeed each implementation
136 of an algorithm can vary. The options for the OpenSSL implementations
137 are detailed below.
138
139 DSA Parameter Generation Options
140 dsa_paramgen_bits:numbits
141 The number of bits in the generated prime. If not specified 2048 is
142 used.
143
144 dsa_paramgen_q_bits:numbits
145 The number of bits in the q parameter. Must be one of 160, 224 or
146 256. If not specified 224 is used.
147
148 dsa_paramgen_md:digest
149 The digest to use during parameter generation. Must be one of sha1,
150 sha224 or sha256. If set, then the number of bits in q will match
151 the output size of the specified digest and the dsa_paramgen_q_bits
152 parameter will be ignored. If not set, then a digest will be used
153 that gives an output matching the number of bits in q, i.e. sha1 if
154 q length is 160, sha224 if it 224 or sha256 if it is 256.
155
156 DH Parameter Generation Options
157 dh_paramgen_prime_len:numbits
158 The number of bits in the prime parameter p. The default is 2048.
159
160 dh_paramgen_subprime_len:numbits
161 The number of bits in the sub prime parameter q. The default is 256
162 if the prime is at least 2048 bits long or 160 otherwise. Only
163 relevant if used in conjunction with the dh_paramgen_type option to
164 generate X9.42 DH parameters.
165
166 dh_paramgen_generator:value
167 The value to use for the generator g. The default is 2.
168
169 dh_paramgen_type:value
170 The type of DH parameters to generate. Use 0 for PKCS#3 DH and 1
171 for X9.42 DH. The default is 0.
172
173 dh_rfc5114:num
174 If this option is set, then the appropriate RFC5114 parameters are
175 used instead of generating new parameters. The value num can take
176 the values 1, 2 or 3 corresponding to RFC5114 DH parameters
177 consisting of 1024 bit group with 160 bit subgroup, 2048 bit group
178 with 224 bit subgroup and 2048 bit group with 256 bit subgroup as
179 mentioned in RFC5114 sections 2.1, 2.2 and 2.3 respectively. If
180 present this overrides all other DH parameter options.
181
182 EC Parameter Generation Options
183 The EC parameter generation options are the same as for key generation.
184 See "EC Key Generation Options" above.
185
187 The use of the genpkey program is encouraged over the algorithm
188 specific utilities because additional algorithm options and ENGINE
189 provided algorithms can be used.
190
192 Generate an RSA private key using default parameters:
193
194 openssl genpkey -algorithm RSA -out key.pem
195
196 Encrypt output private key using 128 bit AES and the passphrase
197 "hello":
198
199 openssl genpkey -algorithm RSA -out key.pem -aes-128-cbc -pass pass:hello
200
201 Generate a 2048 bit RSA key using 3 as the public exponent:
202
203 openssl genpkey -algorithm RSA -out key.pem \
204 -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:3
205
206 Generate 2048 bit DSA parameters:
207
208 openssl genpkey -genparam -algorithm DSA -out dsap.pem \
209 -pkeyopt dsa_paramgen_bits:2048
210
211 Generate DSA key from parameters:
212
213 openssl genpkey -paramfile dsap.pem -out dsakey.pem
214
215 Generate 2048 bit DH parameters:
216
217 openssl genpkey -genparam -algorithm DH -out dhp.pem \
218 -pkeyopt dh_paramgen_prime_len:2048
219
220 Generate 2048 bit X9.42 DH parameters:
221
222 openssl genpkey -genparam -algorithm DH -out dhpx.pem \
223 -pkeyopt dh_paramgen_prime_len:2048 \
224 -pkeyopt dh_paramgen_type:1
225
226 Output RFC5114 2048 bit DH parameters with 224 bit subgroup:
227
228 openssl genpkey -genparam -algorithm DH -out dhp.pem -pkeyopt dh_rfc5114:2
229
230 Generate DH key from parameters:
231
232 openssl genpkey -paramfile dhp.pem -out dhkey.pem
233
234 Generate EC parameters:
235
236 openssl genpkey -genparam -algorithm EC -out ecp.pem \
237 -pkeyopt ec_paramgen_curve:secp384r1 \
238 -pkeyopt ec_param_enc:named_curve
239
240 Generate EC key from parameters:
241
242 openssl genpkey -paramfile ecp.pem -out eckey.pem
243
244 Generate EC key directly:
245
246 openssl genpkey -algorithm EC -out eckey.pem \
247 -pkeyopt ec_paramgen_curve:P-384 \
248 -pkeyopt ec_param_enc:named_curve
249
250 Generate an X25519 private key:
251
252 openssl genpkey -algorithm X25519 -out xkey.pem
253
254 Generate an ED448 private key:
255
256 openssl genpkey -algorithm ED448 -out xkey.pem
257
259 The ability to use NIST curve names, and to generate an EC key
260 directly, were added in OpenSSL 1.0.2. The ability to generate X25519
261 keys was added in OpenSSL 1.1.0. The ability to generate X448, ED25519
262 and ED448 keys was added in OpenSSL 1.1.1.
263
265 Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
266
267 Licensed under the OpenSSL license (the "License"). You may not use
268 this file except in compliance with the License. You can obtain a copy
269 in the file LICENSE in the source distribution or at
270 <https://www.openssl.org/source/license.html>.
271
272
273
2741.1.1l 2021-09-15 GENPKEY(1)