1 1.1 christos =pod 2 1.1 christos {- OpenSSL::safe::output_do_not_edit_headers(); -} 3 1.1 christos 4 1.1 christos =head1 NAME 5 1.1 christos 6 1.1 christos openssl-pkcs8 - PKCS#8 format private key conversion command 7 1.1 christos 8 1.1 christos =head1 SYNOPSIS 9 1.1 christos 10 1.1 christos B<openssl> B<pkcs8> 11 1.1 christos [B<-help>] 12 1.1 christos [B<-topk8>] 13 1.1 christos [B<-inform> B<DER>|B<PEM>] 14 1.1 christos [B<-outform> B<DER>|B<PEM>] 15 1.1 christos [B<-in> I<filename>] 16 1.1 christos [B<-passin> I<arg>] 17 1.1 christos [B<-out> I<filename>] 18 1.1 christos [B<-passout> I<arg>] 19 1.1 christos [B<-iter> I<count>] 20 1.1 christos [B<-noiter>] 21 1.1 christos [B<-nocrypt>] 22 1.1 christos [B<-traditional>] 23 1.1 christos [B<-v2> I<alg>] 24 1.1 christos [B<-v2prf> I<alg>] 25 1.1 christos [B<-v1> I<alg>] 26 1.1 christos [B<-scrypt>] 27 1.1 christos [B<-scrypt_N> I<N>] 28 1.1 christos [B<-scrypt_r> I<r>] 29 1.1 christos [B<-scrypt_p> I<p>] 30 1.1 christos [B<-saltlen> I<size>] 31 1.1 christos {- $OpenSSL::safe::opt_r_synopsis -} 32 1.1 christos {- $OpenSSL::safe::opt_engine_synopsis -}{- $OpenSSL::safe::opt_provider_synopsis -} 33 1.1 christos 34 1.1 christos =head1 DESCRIPTION 35 1.1 christos 36 1.1 christos This command processes private keys in PKCS#8 format. It can handle 37 1.1 christos both unencrypted PKCS#8 PrivateKeyInfo format and EncryptedPrivateKeyInfo 38 1.1 christos format with a variety of PKCS#5 (v1.5 and v2.0) and PKCS#12 algorithms. 39 1.1 christos 40 1.1 christos =head1 OPTIONS 41 1.1 christos 42 1.1 christos =over 4 43 1.1 christos 44 1.1 christos =item B<-help> 45 1.1 christos 46 1.1 christos Print out a usage message. 47 1.1 christos 48 1.1 christos =item B<-topk8> 49 1.1 christos 50 1.1 christos Normally a PKCS#8 private key is expected on input and a private key will be 51 1.1 christos written to the output file. With the B<-topk8> option the situation is 52 1.1 christos reversed: it reads a private key and writes a PKCS#8 format key. 53 1.1 christos 54 1.1 christos =item B<-inform> B<DER>|B<PEM>, B<-outform> B<DER>|B<PEM> 55 1.1 christos 56 1.1 christos The input and formats; the default is B<PEM>. 57 1.1 christos See L<openssl-format-options(1)> for details. 58 1.1 christos 59 1.1 christos If a key is being converted from PKCS#8 form (i.e. the B<-topk8> option is 60 1.1 christos not used) then the input file must be in PKCS#8 format. An encrypted 61 1.1 christos key is expected unless B<-nocrypt> is included. 62 1.1 christos 63 1.1 christos If B<-topk8> is not used and B<PEM> mode is set the output file will be an 64 1.1 christos unencrypted private key in PKCS#8 format. If the B<-traditional> option is 65 1.1 christos used then a traditional format private key is written instead. 66 1.1 christos 67 1.1 christos If B<-topk8> is not used and B<DER> mode is set the output file will be an 68 1.1 christos unencrypted private key in traditional DER format. 69 1.1 christos 70 1.1 christos If B<-topk8> is used then any supported private key can be used for the input 71 1.1 christos file in a format specified by B<-inform>. The output file will be encrypted 72 1.1 christos PKCS#8 format using the specified encryption parameters unless B<-nocrypt> 73 1.1 christos is included. 74 1.1 christos 75 1.1 christos =item B<-traditional> 76 1.1 christos 77 1.1.1.2 christos When this option is present and B<-topk8> is not, a traditional format private 78 1.1 christos key is written. 79 1.1 christos 80 1.1 christos =item B<-in> I<filename> 81 1.1 christos 82 1.1 christos This specifies the input file to read a key from or standard input if this 83 1.1 christos option is not specified. If the key is encrypted a pass phrase will be 84 1.1 christos prompted for unless B<-passin> is given. 85 1.1 christos 86 1.1 christos =item B<-passin> I<arg>, B<-passout> I<arg> 87 1.1 christos 88 1.1 christos The password source for the input and output file. 89 1.1 christos For more information about the format of B<arg> 90 1.1 christos see L<openssl-passphrase-options(1)>. 91 1.1 christos 92 1.1 christos =item B<-out> I<filename> 93 1.1 christos 94 1.1 christos This specifies the output file to write a key to or standard output by default. 95 1.1 christos The output filename can be the same as the input filename, 96 1.1 christos which leads to replacing the file contents. 97 1.1 christos Note that file I/O is not atomic. The output file is truncated and then written. 98 1.1 christos 99 1.1 christos If any encryption options are set and B<-passout> is not given 100 1.1 christos then a pass phrase will be prompted for. 101 1.1 christos When password input is interrupted, the output file is not touched. 102 1.1 christos 103 1.1 christos =item B<-iter> I<count> 104 1.1 christos 105 1.1 christos When creating new PKCS#8 containers, use a given number of iterations on 106 1.1 christos the password in deriving the encryption key for the PKCS#8 output. 107 1.1 christos High values increase the time required to brute-force a PKCS#8 container. 108 1.1 christos 109 1.1 christos =item B<-noiter> 110 1.1 christos 111 1.1 christos When creating new PKCS#8 containers, use 1 as iteration count. 112 1.1 christos 113 1.1 christos =item B<-nocrypt> 114 1.1 christos 115 1.1 christos PKCS#8 keys generated or input are normally PKCS#8 EncryptedPrivateKeyInfo 116 1.1 christos structures using an appropriate password based encryption algorithm. With 117 1.1 christos this option an unencrypted PrivateKeyInfo structure is expected or output. 118 1.1 christos This option does not encrypt private keys at all and should only be used 119 1.1 christos when absolutely necessary. Certain software such as some versions of Java 120 1.1 christos code signing software used unencrypted private keys. 121 1.1 christos 122 1.1 christos =item B<-v2> I<alg> 123 1.1 christos 124 1.1 christos This option sets the PKCS#5 v2.0 algorithm. 125 1.1 christos 126 1.1 christos The I<alg> argument is the encryption algorithm to use, valid values include 127 1.1 christos B<aes128>, B<aes256> and B<des3>. If this option isn't specified then B<aes256> 128 1.1 christos is used. 129 1.1 christos 130 1.1 christos =item B<-v2prf> I<alg> 131 1.1 christos 132 1.1 christos This option sets the PRF algorithm to use with PKCS#5 v2.0. A typical value 133 1.1 christos value would be B<hmacWithSHA256>. If this option isn't set then the default 134 1.1 christos for the cipher is used or B<hmacWithSHA256> if there is no default. 135 1.1 christos 136 1.1 christos Some implementations may not support custom PRF algorithms and may require 137 1.1 christos the B<hmacWithSHA1> option to work. 138 1.1 christos 139 1.1 christos =item B<-v1> I<alg> 140 1.1 christos 141 1.1 christos This option indicates a PKCS#5 v1.5 or PKCS#12 algorithm should be used. Some 142 1.1 christos older implementations may not support PKCS#5 v2.0 and may require this option. 143 1.1 christos If not specified PKCS#5 v2.0 form is used. 144 1.1 christos 145 1.1 christos =item B<-scrypt> 146 1.1 christos 147 1.1 christos Uses the B<scrypt> algorithm for private key encryption using default 148 1.1 christos parameters: currently N=16384, r=8 and p=1 and AES in CBC mode with a 256 bit 149 1.1 christos key. These parameters can be modified using the B<-scrypt_N>, B<-scrypt_r>, 150 1.1 christos B<-scrypt_p> and B<-v2> options. 151 1.1 christos 152 1.1 christos =item B<-scrypt_N> I<N>, B<-scrypt_r> I<r>, B<-scrypt_p> I<p> 153 1.1 christos 154 1.1 christos Sets the scrypt I<N>, I<r> or I<p> parameters. 155 1.1 christos 156 1.1 christos =item B<-saltlen> 157 1.1 christos 158 1.1 christos Sets the length (in bytes) of the salt to use for the PBE algorithm. 159 1.1 christos If this value is not specified, the default for PBES2 is 16 (128 bits) 160 1.1 christos and 8 (64 bits) for PBES1. 161 1.1 christos 162 1.1 christos {- $OpenSSL::safe::opt_r_item -} 163 1.1 christos 164 1.1 christos {- $OpenSSL::safe::opt_engine_item -} 165 1.1 christos 166 1.1 christos {- $OpenSSL::safe::opt_provider_item -} 167 1.1 christos 168 1.1 christos =back 169 1.1 christos 170 1.1 christos =head1 NOTES 171 1.1 christos 172 1.1 christos By default, when converting a key to PKCS#8 format, PKCS#5 v2.0 using 256 bit 173 1.1 christos AES with HMAC and SHA256 is used. 174 1.1 christos 175 1.1 christos Some older implementations do not support PKCS#5 v2.0 format and require 176 1.1 christos the older PKCS#5 v1.5 form instead, possibly also requiring insecure weak 177 1.1 christos encryption algorithms such as 56 bit DES. 178 1.1 christos 179 1.1 christos Private keys encrypted using PKCS#5 v2.0 algorithms and high iteration 180 1.1 christos counts are more secure that those encrypted using the traditional 181 1.1 christos SSLeay compatible formats. So if additional security is considered 182 1.1 christos important the keys should be converted. 183 1.1 christos 184 1.1 christos It is possible to write out DER encoded encrypted private keys in 185 1.1 christos PKCS#8 format because the encryption details are included at an ASN1 186 1.1 christos level whereas the traditional format includes them at a PEM level. 187 1.1 christos 188 1.1 christos =head1 PKCS#5 V1.5 AND PKCS#12 ALGORITHMS 189 1.1 christos 190 1.1 christos Various algorithms can be used with the B<-v1> command line option, 191 1.1 christos including PKCS#5 v1.5 and PKCS#12. These are described in more detail 192 1.1 christos below. 193 1.1 christos 194 1.1 christos =over 4 195 1.1 christos 196 1.1 christos =item B<PBE-MD2-DES PBE-MD5-DES> 197 1.1 christos 198 1.1 christos These algorithms were included in the original PKCS#5 v1.5 specification. 199 1.1 christos They only offer 56 bits of protection since they both use DES. 200 1.1 christos 201 1.1 christos =item B<PBE-SHA1-RC2-64>, B<PBE-MD2-RC2-64>, B<PBE-MD5-RC2-64>, B<PBE-SHA1-DES> 202 1.1 christos 203 1.1 christos These algorithms are not mentioned in the original PKCS#5 v1.5 specification 204 1.1 christos but they use the same key derivation algorithm and are supported by some 205 1.1 christos software. They are mentioned in PKCS#5 v2.0. They use either 64 bit RC2 or 206 1.1 christos 56 bit DES. 207 1.1 christos 208 1.1 christos =item B<PBE-SHA1-RC4-128>, B<PBE-SHA1-RC4-40>, B<PBE-SHA1-3DES>, B<PBE-SHA1-2DES>, B<PBE-SHA1-RC2-128>, B<PBE-SHA1-RC2-40> 209 1.1 christos 210 1.1 christos These algorithms use the PKCS#12 password based encryption algorithm and 211 1.1 christos allow strong encryption algorithms like triple DES or 128 bit RC2 to be used. 212 1.1 christos 213 1.1 christos =back 214 1.1 christos 215 1.1 christos =head1 EXAMPLES 216 1.1 christos 217 1.1 christos Convert a private key to PKCS#8 format using default parameters (AES with 218 1.1 christos 256 bit key and B<hmacWithSHA256>): 219 1.1 christos 220 1.1 christos openssl pkcs8 -in key.pem -topk8 -out enckey.pem 221 1.1 christos 222 1.1 christos Convert a private key to PKCS#8 unencrypted format: 223 1.1 christos 224 1.1 christos openssl pkcs8 -in key.pem -topk8 -nocrypt -out enckey.pem 225 1.1 christos 226 1.1 christos Convert a private key to PKCS#5 v2.0 format using triple DES: 227 1.1 christos 228 1.1 christos openssl pkcs8 -in key.pem -topk8 -v2 des3 -out enckey.pem 229 1.1 christos 230 1.1 christos Convert a private key to PKCS#5 v2.0 format using AES with 256 bits in CBC 231 1.1 christos mode and B<hmacWithSHA512> PRF: 232 1.1 christos 233 1.1 christos openssl pkcs8 -in key.pem -topk8 -v2 aes-256-cbc -v2prf hmacWithSHA512 -out enckey.pem 234 1.1 christos 235 1.1 christos Convert a private key to PKCS#8 using a PKCS#5 1.5 compatible algorithm 236 1.1 christos (DES): 237 1.1 christos 238 1.1 christos openssl pkcs8 -in key.pem -topk8 -v1 PBE-MD5-DES -out enckey.pem 239 1.1 christos 240 1.1 christos Convert a private key to PKCS#8 using a PKCS#12 compatible algorithm 241 1.1 christos (3DES): 242 1.1 christos 243 1.1 christos openssl pkcs8 -in key.pem -topk8 -out enckey.pem -v1 PBE-SHA1-3DES 244 1.1 christos 245 1.1 christos Read a DER unencrypted PKCS#8 format private key: 246 1.1 christos 247 1.1 christos openssl pkcs8 -inform DER -nocrypt -in key.der -out key.pem 248 1.1 christos 249 1.1 christos Convert a private key from any PKCS#8 encrypted format to traditional format: 250 1.1 christos 251 1.1 christos openssl pkcs8 -in pk8.pem -traditional -out key.pem 252 1.1 christos 253 1.1 christos Convert a private key to PKCS#8 format, encrypting with AES-256 and with 254 1.1 christos one million iterations of the password: 255 1.1 christos 256 1.1 christos openssl pkcs8 -in key.pem -topk8 -v2 aes-256-cbc -iter 1000000 -out pk8.pem 257 1.1 christos 258 1.1 christos =head1 STANDARDS 259 1.1 christos 260 1.1 christos Test vectors from this PKCS#5 v2.0 implementation were posted to the 261 1.1 christos pkcs-tng mailing list using triple DES, DES and RC2 with high iteration 262 1.1 christos counts, several people confirmed that they could decrypt the private 263 1.1 christos keys produced and therefore, it can be assumed that the PKCS#5 v2.0 264 1.1 christos implementation is reasonably accurate at least as far as these 265 1.1 christos algorithms are concerned. 266 1.1 christos 267 1.1 christos The format of PKCS#8 DSA (and other) private keys is not well documented: 268 1.1 christos it is hidden away in PKCS#11 v2.01, section 11.9. OpenSSL's default DSA 269 1.1 christos PKCS#8 private key format complies with this standard. 270 1.1 christos 271 1.1 christos =head1 BUGS 272 1.1 christos 273 1.1 christos There should be an option that prints out the encryption algorithm 274 1.1 christos in use and other details such as the iteration count. 275 1.1 christos 276 1.1 christos =head1 SEE ALSO 277 1.1 christos 278 1.1 christos L<openssl(1)>, 279 1.1 christos L<openssl-dsa(1)>, 280 1.1 christos L<openssl-rsa(1)>, 281 1.1 christos L<openssl-genrsa(1)>, 282 1.1 christos L<openssl-gendsa(1)> 283 1.1 christos 284 1.1 christos =head1 HISTORY 285 1.1 christos 286 1.1 christos The B<-iter> option was added in OpenSSL 1.1.0. 287 1.1 christos 288 1.1 christos The B<-engine> option was deprecated in OpenSSL 3.0. 289 1.1 christos 290 1.1 christos =head1 COPYRIGHT 291 1.1 christos 292 1.1.1.2 christos Copyright 2000-2026 The OpenSSL Project Authors. All Rights Reserved. 293 1.1 christos 294 1.1 christos Licensed under the Apache License 2.0 (the "License"). You may not use 295 1.1 christos this file except in compliance with the License. You can obtain a copy 296 1.1 christos in the file LICENSE in the source distribution or at 297 1.1 christos L<https://www.openssl.org/source/license.html>. 298 1.1 christos 299 1.1 christos =cut 300