xref: /freebsd/secure/usr.bin/openssl/man/openssl-pkcs8.1 (revision 174c0ac687ec4ccb0b56ee30d48c0a7b8b9c4e15)
Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)

Standard preamble:
========================================================================
..
..
.. Set up some character translations and predefined strings. \*(-- will
give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
double quote, and \*(R" will give a right double quote. \*(C+ will
give a nicer C++. Capital omega is used to do unbreakable dashes and
therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
nothing in troff, for use with C<>.
.tr \(*W- . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\}
Escape single quotes in literal strings from groff's Unicode transform.

If the F register is >0, we'll generate index entries on stderr for
titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
entries marked with X<> in POD. Of course, you'll have to process the
output yourself in some meaningful fashion.

Avoid warning from groff about undefined register 'F'.
.. .nr rF 0 . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] .\} . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents . \" corrections for vroff . \" for low resolution devices (crt and lpr) \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} ========================================================================

Title "OPENSSL-PKCS8 1ossl"
OPENSSL-PKCS8 1ossl "2023-09-22" "3.0.11" "OpenSSL"
For nroff, turn off justification. Always turn off hyphenation; it makes
way too many mistakes in technical documents.
"NAME"
openssl-pkcs8 - PKCS#8 format private key conversion command
"SYNOPSIS"
Header "SYNOPSIS" \fBopenssl pkcs8 [-help] [-topk8] [-inform \s-1DER\s0|\s-1PEM\s0] [-outform \s-1DER\s0|\s-1PEM\s0] [-in filename] [-passin arg] [-out filename] [-passout arg] [-iter count] [-noiter] [-nocrypt] [-traditional] [-v2 alg] [-v2prf alg] [-v1 alg] [-scrypt] [-scrypt_N N] [-scrypt_r r] [-scrypt_p p] [-rand files] [-writerand file] [-engine id] [-provider name] [-provider-path path] [-propquery propq]
"DESCRIPTION"
Header "DESCRIPTION" This command processes private keys in PKCS#8 format. It can handle both unencrypted PKCS#8 PrivateKeyInfo format and EncryptedPrivateKeyInfo format with a variety of PKCS#5 (v1.5 and v2.0) and PKCS#12 algorithms.
"OPTIONS"
Header "OPTIONS"
"-help" 4
Item "-help" Print out a usage message.
"-topk8" 4
Item "-topk8" Normally a PKCS#8 private key is expected on input and a private key will be written to the output file. With the -topk8 option the situation is reversed: it reads a private key and writes a PKCS#8 format key.
"-inform \s-1DER\s0|\s-1PEM\s0, -outform \s-1DER\s0|\s-1PEM\s0" 4
Item "-inform DER|PEM, -outform DER|PEM" The input and formats; the default is \s-1PEM\s0. See openssl-format-options\|(1) for details. .Sp If a key is being converted from PKCS#8 form (i.e. the -topk8 option is not used) then the input file must be in PKCS#8 format. An encrypted key is expected unless -nocrypt is included. .Sp If -topk8 is not used and \s-1PEM\s0 mode is set the output file will be an unencrypted private key in PKCS#8 format. If the -traditional option is used then a traditional format private key is written instead. .Sp If -topk8 is not used and \s-1DER\s0 mode is set the output file will be an unencrypted private key in traditional \s-1DER\s0 format. .Sp If -topk8 is used then any supported private key can be used for the input file in a format specified by -inform. The output file will be encrypted PKCS#8 format using the specified encryption parameters unless -nocrypt is included.
"-traditional" 4
Item "-traditional" When this option is present and -topk8 is not a traditional format private key is written.
"-in filename" 4
Item "-in filename" This specifies the input filename to read a key from or standard input if this option is not specified. If the key is encrypted a pass phrase will be prompted for.
"-passin arg, -passout arg" 4
Item "-passin arg, -passout arg" The password source for the input and output file. For more information about the format of arg see openssl-passphrase-options\|(1).
"-out filename" 4
Item "-out filename" This specifies the output filename to write a key to or standard output by default. If any encryption options are set then a pass phrase will be prompted for. The output filename should not be the same as the input filename.
"-iter count" 4
Item "-iter count" When creating new PKCS#8 containers, use a given number of iterations on the password in deriving the encryption key for the PKCS#8 output. High values increase the time required to brute-force a PKCS#8 container.
"-noiter" 4
Item "-noiter" When creating new PKCS#8 containers, use 1 as iteration count.
"-nocrypt" 4
Item "-nocrypt" PKCS#8 keys generated or input are normally PKCS#8 EncryptedPrivateKeyInfo structures using an appropriate password based encryption algorithm. With this option an unencrypted PrivateKeyInfo structure is expected or output. This option does not encrypt private keys at all and should only be used when absolutely necessary. Certain software such as some versions of Java code signing software used unencrypted private keys.
"-v2 alg" 4
Item "-v2 alg" This option sets the PKCS#5 v2.0 algorithm. .Sp The alg argument is the encryption algorithm to use, valid values include \fBaes128, aes256 and des3. If this option isn't specified then aes256 is used.
"-v2prf alg" 4
Item "-v2prf alg" This option sets the \s-1PRF\s0 algorithm to use with PKCS#5 v2.0. A typical value value would be hmacWithSHA256. If this option isn't set then the default for the cipher is used or hmacWithSHA256 if there is no default. .Sp Some implementations may not support custom \s-1PRF\s0 algorithms and may require the hmacWithSHA1 option to work.
"-v1 alg" 4
Item "-v1 alg" This option indicates a PKCS#5 v1.5 or PKCS#12 algorithm should be used. Some older implementations may not support PKCS#5 v2.0 and may require this option. If not specified PKCS#5 v2.0 form is used.
"-scrypt" 4
Item "-scrypt" Uses the scrypt algorithm for private key encryption using default parameters: currently N=16384, r=8 and p=1 and \s-1AES\s0 in \s-1CBC\s0 mode with a 256 bit key. These parameters can be modified using the -scrypt_N, -scrypt_r, \fB-scrypt_p and -v2 options.
"-scrypt_N N, -scrypt_r r, -scrypt_p p" 4
Item "-scrypt_N N, -scrypt_r r, -scrypt_p p" Sets the scrypt N, r or p parameters.
"-rand files, -writerand file" 4
Item "-rand files, -writerand file" See \*(L"Random State Options\*(R" in openssl\|(1) for details.
"-engine id" 4
Item "-engine id" See \*(L"Engine Options\*(R" in openssl\|(1). This option is deprecated.
"-provider name" 4
Item "-provider name"

0

"-provider-path path" 4
Item "-provider-path path"
"-propquery propq" 4
Item "-propquery propq"

See \*(L"Provider Options\*(R" in openssl\|(1), provider\|(7), and property\|(7).

"NOTES"
Header "NOTES" By default, when converting a key to PKCS#8 format, PKCS#5 v2.0 using 256 bit \s-1AES\s0 with \s-1HMAC\s0 and \s-1SHA256\s0 is used.

Some older implementations do not support PKCS#5 v2.0 format and require the older PKCS#5 v1.5 form instead, possibly also requiring insecure weak encryption algorithms such as 56 bit \s-1DES.\s0

Private keys encrypted using PKCS#5 v2.0 algorithms and high iteration counts are more secure that those encrypted using the traditional SSLeay compatible formats. So if additional security is considered important the keys should be converted.

It is possible to write out \s-1DER\s0 encoded encrypted private keys in PKCS#8 format because the encryption details are included at an \s-1ASN1\s0 level whereas the traditional format includes them at a \s-1PEM\s0 level.

"PKCS#5 V1.5 AND PKCS#12 ALGORITHMS"
Header "PKCS#5 V1.5 AND PKCS#12 ALGORITHMS" Various algorithms can be used with the -v1 command line option, including PKCS#5 v1.5 and PKCS#12. These are described in more detail below.
"\s-1PBE-MD2-DES PBE-MD5-DES\s0" 4
Item "PBE-MD2-DES PBE-MD5-DES" These algorithms were included in the original PKCS#5 v1.5 specification. They only offer 56 bits of protection since they both use \s-1DES.\s0
"\s-1PBE-SHA1-RC2-64\s0, \s-1PBE-MD2-RC2-64\s0, \s-1PBE-MD5-RC2-64\s0, \s-1PBE-SHA1-DES\s0" 4
Item "PBE-SHA1-RC2-64, PBE-MD2-RC2-64, PBE-MD5-RC2-64, PBE-SHA1-DES" These algorithms are not mentioned in the original PKCS#5 v1.5 specification but they use the same key derivation algorithm and are supported by some software. They are mentioned in PKCS#5 v2.0. They use either 64 bit \s-1RC2\s0 or 56 bit \s-1DES.\s0
"\s-1PBE-SHA1-RC4-128\s0, \s-1PBE-SHA1-RC4-40\s0, \s-1PBE-SHA1-3DES\s0, \s-1PBE-SHA1-2DES\s0, \s-1PBE-SHA1-RC2-128\s0, \s-1PBE-SHA1-RC2-40\s0" 4
Item "PBE-SHA1-RC4-128, PBE-SHA1-RC4-40, PBE-SHA1-3DES, PBE-SHA1-2DES, PBE-SHA1-RC2-128, PBE-SHA1-RC2-40" These algorithms use the PKCS#12 password based encryption algorithm and allow strong encryption algorithms like triple \s-1DES\s0 or 128 bit \s-1RC2\s0 to be used.
"EXAMPLES"
Header "EXAMPLES" Convert a private key to PKCS#8 format using default parameters (\s-1AES\s0 with 256 bit key and hmacWithSHA256):

.Vb 1 openssl pkcs8 -in key.pem -topk8 -out enckey.pem .Ve

Convert a private key to PKCS#8 unencrypted format:

.Vb 1 openssl pkcs8 -in key.pem -topk8 -nocrypt -out enckey.pem .Ve

Convert a private key to PKCS#5 v2.0 format using triple \s-1DES:\s0

.Vb 1 openssl pkcs8 -in key.pem -topk8 -v2 des3 -out enckey.pem .Ve

Convert a private key to PKCS#5 v2.0 format using \s-1AES\s0 with 256 bits in \s-1CBC\s0 mode and hmacWithSHA512 \s-1PRF:\s0

.Vb 1 openssl pkcs8 -in key.pem -topk8 -v2 aes-256-cbc -v2prf hmacWithSHA512 -out enckey.pem .Ve

Convert a private key to PKCS#8 using a PKCS#5 1.5 compatible algorithm (\s-1DES\s0):

.Vb 1 openssl pkcs8 -in key.pem -topk8 -v1 PBE-MD5-DES -out enckey.pem .Ve

Convert a private key to PKCS#8 using a PKCS#12 compatible algorithm (3DES):

.Vb 1 openssl pkcs8 -in key.pem -topk8 -out enckey.pem -v1 PBE-SHA1-3DES .Ve

Read a \s-1DER\s0 unencrypted PKCS#8 format private key:

.Vb 1 openssl pkcs8 -inform DER -nocrypt -in key.der -out key.pem .Ve

Convert a private key from any PKCS#8 encrypted format to traditional format:

.Vb 1 openssl pkcs8 -in pk8.pem -traditional -out key.pem .Ve

Convert a private key to PKCS#8 format, encrypting with \s-1AES-256\s0 and with one million iterations of the password:

.Vb 1 openssl pkcs8 -in key.pem -topk8 -v2 aes-256-cbc -iter 1000000 -out pk8.pem .Ve

"STANDARDS"
Header "STANDARDS" Test vectors from this PKCS#5 v2.0 implementation were posted to the pkcs-tng mailing list using triple \s-1DES, DES\s0 and \s-1RC2\s0 with high iteration counts, several people confirmed that they could decrypt the private keys produced and therefore, it can be assumed that the PKCS#5 v2.0 implementation is reasonably accurate at least as far as these algorithms are concerned.

The format of PKCS#8 \s-1DSA\s0 (and other) private keys is not well documented: it is hidden away in PKCS#11 v2.01, section 11.9. OpenSSL's default \s-1DSA\s0 PKCS#8 private key format complies with this standard.

"BUGS"
Header "BUGS" There should be an option that prints out the encryption algorithm in use and other details such as the iteration count.
"SEE ALSO"
Header "SEE ALSO" \fBopenssl\|(1), \fBopenssl-dsa\|(1), \fBopenssl-rsa\|(1), \fBopenssl-genrsa\|(1), \fBopenssl-gendsa\|(1)
"HISTORY"
Header "HISTORY" The -iter option was added in OpenSSL 1.1.0.

The -engine option was deprecated in OpenSSL 3.0.

"COPYRIGHT"
Header "COPYRIGHT" Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use this file except in compliance with the License. You can obtain a copy in the file \s-1LICENSE\s0 in the source distribution or at <https://www.openssl.org/source/license.html>.