Blame doc/man1/genpkey.pod

Packit c4476c
=pod
Packit c4476c
Packit c4476c
=head1 NAME
Packit c4476c
Packit c4476c
openssl-genpkey,
Packit c4476c
genpkey - generate a private key
Packit c4476c
Packit c4476c
=head1 SYNOPSIS
Packit c4476c
Packit c4476c
B<openssl> B<genpkey>
Packit c4476c
[B<-help>]
Packit c4476c
[B<-out filename>]
Packit c4476c
[B<-outform PEM|DER>]
Packit c4476c
[B<-pass arg>]
Packit c4476c
[B<-I<cipher>>]
Packit c4476c
[B<-engine id>]
Packit c4476c
[B<-paramfile file>]
Packit c4476c
[B<-algorithm alg>]
Packit c4476c
[B<-pkeyopt opt:value>]
Packit c4476c
[B<-genparam>]
Packit c4476c
[B<-text>]
Packit c4476c
Packit c4476c
=head1 DESCRIPTION
Packit c4476c
Packit c4476c
The B<genpkey> command generates a private key.
Packit c4476c
Packit c4476c
=head1 OPTIONS
Packit c4476c
Packit c4476c
=over 4
Packit c4476c
Packit c4476c
=item B<-help>
Packit c4476c
Packit c4476c
Print out a usage message.
Packit c4476c
Packit c4476c
=item B<-out filename>
Packit c4476c
Packit c4476c
Output the key to the specified file. If this argument is not specified then
Packit c4476c
standard output is used.
Packit c4476c
Packit c4476c
=item B<-outform DER|PEM>
Packit c4476c
Packit c4476c
This specifies the output format DER or PEM. The default format is PEM.
Packit c4476c
Packit c4476c
=item B<-pass arg>
Packit c4476c
Packit c4476c
The output file password source. For more information about the format of B<arg>
Packit c4476c
see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)>.
Packit c4476c
Packit c4476c
=item B<-I<cipher>>
Packit c4476c
Packit c4476c
This option encrypts the private key with the supplied cipher. Any algorithm
Packit c4476c
name accepted by EVP_get_cipherbyname() is acceptable such as B<des3>.
Packit c4476c
Packit c4476c
=item B<-engine id>
Packit c4476c
Packit c4476c
Specifying an engine (by its unique B<id> string) will cause B<genpkey>
Packit c4476c
to attempt to obtain a functional reference to the specified engine,
Packit c4476c
thus initialising it if needed. The engine will then be set as the default
Packit c4476c
for all available algorithms. If used this option should precede all other
Packit c4476c
options.
Packit c4476c
Packit c4476c
=item B<-algorithm alg>
Packit c4476c
Packit c4476c
Public key algorithm to use such as RSA, DSA or DH. If used this option must
Packit c4476c
precede any B<-pkeyopt> options. The options B<-paramfile> and B<-algorithm>
Packit c4476c
are mutually exclusive. Engines may add algorithms in addition to the standard
Packit c4476c
built-in ones.
Packit c4476c
Packit c4476c
Valid built-in algorithm names for private key generation are RSA, RSA-PSS, EC,
Packit c4476c
X25519, X448, ED25519 and ED448.
Packit c4476c
Packit c4476c
Valid built-in algorithm names for parameter generation (see the B<-genparam>
Packit c4476c
option) are DH, DSA and EC.
Packit c4476c
Packit c4476c
Note that the algorithm name X9.42 DH may be used as a synonym for the DH
Packit c4476c
algorithm. These are identical and do not indicate the type of parameters that
Packit c4476c
will be generated. Use the B<dh_paramgen_type> option to indicate whether PKCS#3
Packit c4476c
or X9.42 DH parameters are required. See L<DH Parameter Generation Options>
Packit c4476c
below for more details.
Packit c4476c
Packit c4476c
=item B<-pkeyopt opt:value>
Packit c4476c
Packit c4476c
Set the public key algorithm option B<opt> to B<value>. The precise set of
Packit c4476c
options supported depends on the public key algorithm used and its
Packit c4476c
implementation. See L<KEY GENERATION OPTIONS> and
Packit c4476c
L<PARAMETER GENERATION OPTIONS> below for more details.
Packit c4476c
Packit c4476c
=item B<-genparam>
Packit c4476c
Packit c4476c
Generate a set of parameters instead of a private key. If used this option must
Packit c4476c
precede any B<-algorithm>, B<-paramfile> or B<-pkeyopt> options.
Packit c4476c
Packit c4476c
=item B<-paramfile filename>
Packit c4476c
Packit c4476c
Some public key algorithms generate a private key based on a set of parameters.
Packit c4476c
They can be supplied using this option. If this option is used the public key
Packit c4476c
algorithm used is determined by the parameters. If used this option must
Packit c4476c
precede any B<-pkeyopt> options. The options B<-paramfile> and B<-algorithm>
Packit c4476c
are mutually exclusive.
Packit c4476c
Packit c4476c
=item B<-text>
Packit c4476c
Packit c4476c
Print an (unencrypted) text representation of private and public keys and
Packit c4476c
parameters along with the PEM or DER structure.
Packit c4476c
Packit c4476c
=back
Packit c4476c
Packit c4476c
=head1 KEY GENERATION OPTIONS
Packit c4476c
Packit c4476c
The options supported by each algorithm and indeed each implementation of an
Packit c4476c
algorithm can vary. The options for the OpenSSL implementations are detailed
Packit c4476c
below. There are no key generation options defined for the X25519, X448, ED25519
Packit c4476c
or ED448 algorithms.
Packit c4476c
Packit c4476c
=head2 RSA Key Generation Options
Packit c4476c
Packit c4476c
=over 4
Packit c4476c
Packit c4476c
=item B<rsa_keygen_bits:numbits>
Packit c4476c
Packit c4476c
The number of bits in the generated key. If not specified 2048 is used.
Packit c4476c
Packit c4476c
=item B<rsa_keygen_primes:numprimes>
Packit c4476c
Packit c4476c
The number of primes in the generated key. If not specified 2 is used.
Packit c4476c
Packit c4476c
=item B<rsa_keygen_pubexp:value>
Packit c4476c
Packit c4476c
The RSA public exponent value. This can be a large decimal or
Packit c4476c
hexadecimal value if preceded by B<0x>. Default value is 65537.
Packit c4476c
Packit c4476c
=back
Packit c4476c
Packit c4476c
=head2 RSA-PSS Key Generation Options
Packit c4476c
Packit c4476c
Note: by default an B<RSA-PSS> key has no parameter restrictions.
Packit c4476c
Packit c4476c
=over 4
Packit c4476c
Packit c4476c
=item B<rsa_keygen_bits:numbits>, B<rsa_keygen_primes:numprimes>,  B<rsa_keygen_pubexp:value>
Packit c4476c
Packit c4476c
These options have the same meaning as the B<RSA> algorithm.
Packit c4476c
Packit c4476c
=item B<rsa_pss_keygen_md:digest>
Packit c4476c
Packit c4476c
If set the key is restricted and can only use B<digest> for signing.
Packit c4476c
Packit c4476c
=item B<rsa_pss_keygen_mgf1_md:digest>
Packit c4476c
Packit c4476c
If set the key is restricted and can only use B<digest> as it's MGF1
Packit c4476c
parameter.
Packit c4476c
Packit c4476c
=item B<rsa_pss_keygen_saltlen:len>
Packit c4476c
Packit c4476c
If set the key is restricted and B<len> specifies the minimum salt length.
Packit c4476c
Packit c4476c
=back
Packit c4476c
Packit c4476c
=head2 EC Key Generation Options
Packit c4476c
Packit c4476c
The EC key generation options can also be used for parameter generation.
Packit c4476c
Packit c4476c
=over 4
Packit c4476c
Packit c4476c
=item B<ec_paramgen_curve:curve>
Packit c4476c
Packit c4476c
The EC curve to use. OpenSSL supports NIST curve names such as "P-256".
Packit c4476c
Packit c4476c
=item B<ec_param_enc:encoding>
Packit c4476c
Packit c4476c
The encoding to use for parameters. The "encoding" parameter must be either
Packit c4476c
"named_curve" or "explicit". The default value is "named_curve".
Packit c4476c
Packit c4476c
=back
Packit c4476c
Packit c4476c
=head1 PARAMETER GENERATION OPTIONS
Packit c4476c
Packit c4476c
The options supported by each algorithm and indeed each implementation of an
Packit c4476c
algorithm can vary. The options for the OpenSSL implementations are detailed
Packit c4476c
below.
Packit c4476c
Packit c4476c
=head2 DSA Parameter Generation Options
Packit c4476c
Packit c4476c
=over 4
Packit c4476c
Packit c4476c
=item B<dsa_paramgen_bits:numbits>
Packit c4476c
Packit c4476c
The number of bits in the generated prime. If not specified 2048 is used.
Packit c4476c
Packit c4476c
=item B<dsa_paramgen_q_bits:numbits>
Packit c4476c
Packit c4476c
The number of bits in the q parameter. Must be one of 160, 224 or 256. If not
Packit c4476c
specified 224 is used.
Packit c4476c
Packit c4476c
=item B<dsa_paramgen_md:digest>
Packit c4476c
Packit c4476c
The digest to use during parameter generation. Must be one of B<sha1>, B<sha224>
Packit c4476c
or B<sha256>. If set, then the number of bits in B<q> will match the output size
Packit c4476c
of the specified digest and the B<dsa_paramgen_q_bits> parameter will be
Packit c4476c
ignored. If not set, then a digest will be used that gives an output matching
Packit c4476c
the number of bits in B<q>, i.e. B<sha1> if q length is 160, B<sha224> if it 224
Packit c4476c
or B<sha256> if it is 256.
Packit c4476c
Packit c4476c
=back
Packit c4476c
Packit c4476c
=head2 DH Parameter Generation Options
Packit c4476c
Packit c4476c
=over 4
Packit c4476c
Packit c4476c
=item B<dh_paramgen_prime_len:numbits>
Packit c4476c
Packit c4476c
The number of bits in the prime parameter B

. The default is 2048.

Packit c4476c
Packit c4476c
=item B<dh_paramgen_subprime_len:numbits>
Packit c4476c
Packit c4476c
The number of bits in the sub prime parameter B<q>. The default is 256 if the
Packit c4476c
prime is at least 2048 bits long or 160 otherwise. Only relevant if used in
Packit c4476c
conjunction with the B<dh_paramgen_type> option to generate X9.42 DH parameters.
Packit c4476c
Packit c4476c
=item B<dh_paramgen_generator:value>
Packit c4476c
Packit c4476c
The value to use for the generator B<g>. The default is 2.
Packit c4476c
Packit c4476c
=item B<dh_paramgen_type:value>
Packit c4476c
Packit c4476c
The type of DH parameters to generate. Use 0 for PKCS#3 DH and 1 for X9.42 DH.
Packit c4476c
The default is 0.
Packit c4476c
Packit c4476c
=item B<dh_rfc5114:num>
Packit c4476c
Packit c4476c
If this option is set, then the appropriate RFC5114 parameters are used
Packit c4476c
instead of generating new parameters. The value B<num> can take the
Packit c4476c
values 1, 2 or 3 corresponding to RFC5114 DH parameters consisting of
Packit c4476c
1024 bit group with 160 bit subgroup, 2048 bit group with 224 bit subgroup
Packit c4476c
and 2048 bit group with 256 bit subgroup as mentioned in RFC5114 sections
Packit c4476c
2.1, 2.2 and 2.3 respectively. If present this overrides all other DH parameter
Packit c4476c
options.
Packit c4476c
Packit c4476c
=back
Packit c4476c
Packit c4476c
=head2 EC Parameter Generation Options
Packit c4476c
Packit c4476c
The EC parameter generation options are the same as for key generation. See
Packit c4476c
L<EC Key Generation Options> above.
Packit c4476c
Packit c4476c
=head1 NOTES
Packit c4476c
Packit c4476c
The use of the genpkey program is encouraged over the algorithm specific
Packit c4476c
utilities because additional algorithm options and ENGINE provided algorithms
Packit c4476c
can be used.
Packit c4476c
Packit c4476c
=head1 EXAMPLES
Packit c4476c
Packit c4476c
Generate an RSA private key using default parameters:
Packit c4476c
Packit c4476c
 openssl genpkey -algorithm RSA -out key.pem
Packit c4476c
Packit c4476c
Encrypt output private key using 128 bit AES and the passphrase "hello":
Packit c4476c
Packit c4476c
 openssl genpkey -algorithm RSA -out key.pem -aes-128-cbc -pass pass:hello
Packit c4476c
Packit c4476c
Generate a 2048 bit RSA key using 3 as the public exponent:
Packit c4476c
Packit c4476c
 openssl genpkey -algorithm RSA -out key.pem \
Packit c4476c
     -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:3
Packit c4476c
Packit c4476c
Generate 2048 bit DSA parameters:
Packit c4476c
Packit c4476c
 openssl genpkey -genparam -algorithm DSA -out dsap.pem \
Packit c4476c
     -pkeyopt dsa_paramgen_bits:2048
Packit c4476c
Packit c4476c
Generate DSA key from parameters:
Packit c4476c
Packit c4476c
 openssl genpkey -paramfile dsap.pem -out dsakey.pem
Packit c4476c
Packit c4476c
Generate 2048 bit DH parameters:
Packit c4476c
Packit c4476c
 openssl genpkey -genparam -algorithm DH -out dhp.pem \
Packit c4476c
     -pkeyopt dh_paramgen_prime_len:2048
Packit c4476c
Packit c4476c
Generate 2048 bit X9.42 DH parameters:
Packit c4476c
Packit c4476c
 openssl genpkey -genparam -algorithm DH -out dhpx.pem \
Packit c4476c
     -pkeyopt dh_paramgen_prime_len:2048 \
Packit c4476c
     -pkeyopt dh_paramgen_type:1
Packit c4476c
Packit c4476c
Output RFC5114 2048 bit DH parameters with 224 bit subgroup:
Packit c4476c
Packit c4476c
 openssl genpkey -genparam -algorithm DH -out dhp.pem -pkeyopt dh_rfc5114:2
Packit c4476c
Packit c4476c
Generate DH key from parameters:
Packit c4476c
Packit c4476c
 openssl genpkey -paramfile dhp.pem -out dhkey.pem
Packit c4476c
Packit c4476c
Generate EC parameters:
Packit c4476c
Packit c4476c
 openssl genpkey -genparam -algorithm EC -out ecp.pem \
Packit c4476c
        -pkeyopt ec_paramgen_curve:secp384r1 \
Packit c4476c
        -pkeyopt ec_param_enc:named_curve
Packit c4476c
Packit c4476c
Generate EC key from parameters:
Packit c4476c
Packit c4476c
 openssl genpkey -paramfile ecp.pem -out eckey.pem
Packit c4476c
Packit c4476c
Generate EC key directly:
Packit c4476c
Packit c4476c
 openssl genpkey -algorithm EC -out eckey.pem \
Packit c4476c
        -pkeyopt ec_paramgen_curve:P-384 \
Packit c4476c
        -pkeyopt ec_param_enc:named_curve
Packit c4476c
Packit c4476c
Generate an X25519 private key:
Packit c4476c
Packit c4476c
 openssl genpkey -algorithm X25519 -out xkey.pem
Packit c4476c
Packit c4476c
Generate an ED448 private key:
Packit c4476c
Packit c4476c
 openssl genpkey -algorithm ED448 -out xkey.pem
Packit c4476c
Packit c4476c
=head1 HISTORY
Packit c4476c
Packit c4476c
The ability to use NIST curve names, and to generate an EC key directly,
Packit c4476c
were added in OpenSSL 1.0.2.
Packit c4476c
The ability to generate X25519 keys was added in OpenSSL 1.1.0.
Packit c4476c
The ability to generate X448, ED25519 and ED448 keys was added in OpenSSL 1.1.1.
Packit c4476c
Packit c4476c
=head1 COPYRIGHT
Packit c4476c
Packit c4476c
Copyright 2006-2019 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
Packit c4476c
Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
this file except in compliance with the License.  You can obtain a copy
Packit c4476c
in the file LICENSE in the source distribution or at
Packit c4476c
L<https://www.openssl.org/source/license.html>.
Packit c4476c
Packit c4476c
=cut