openssl-pkcs8.1ossl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "OPENSSL-PKCS8 1ossl"
  58. .TH OPENSSL-PKCS8 1ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. openssl\-pkcs8 \- PKCS#8 format private key conversion command
  65. .SH SYNOPSIS
  66. .IX Header "SYNOPSIS"
  67. \&\fBopenssl\fR \fBpkcs8\fR
  68. [\fB\-help\fR]
  69. [\fB\-topk8\fR]
  70. [\fB\-inform\fR \fBDER\fR|\fBPEM\fR]
  71. [\fB\-outform\fR \fBDER\fR|\fBPEM\fR]
  72. [\fB\-in\fR \fIfilename\fR]
  73. [\fB\-passin\fR \fIarg\fR]
  74. [\fB\-out\fR \fIfilename\fR]
  75. [\fB\-passout\fR \fIarg\fR]
  76. [\fB\-iter\fR \fIcount\fR]
  77. [\fB\-noiter\fR]
  78. [\fB\-nocrypt\fR]
  79. [\fB\-traditional\fR]
  80. [\fB\-v2\fR \fIalg\fR]
  81. [\fB\-v2prf\fR \fIalg\fR]
  82. [\fB\-v1\fR \fIalg\fR]
  83. [\fB\-scrypt\fR]
  84. [\fB\-scrypt_N\fR \fIN\fR]
  85. [\fB\-scrypt_r\fR \fIr\fR]
  86. [\fB\-scrypt_p\fR \fIp\fR]
  87. [\fB\-saltlen\fR \fIsize\fR]
  88. [\fB\-rand\fR \fIfiles\fR]
  89. [\fB\-writerand\fR \fIfile\fR]
  90. [\fB\-engine\fR \fIid\fR]
  91. [\fB\-provider\fR \fIname\fR]
  92. [\fB\-provider\-path\fR \fIpath\fR]
  93. [\fB\-propquery\fR \fIpropq\fR]
  94. .SH DESCRIPTION
  95. .IX Header "DESCRIPTION"
  96. This command processes private keys in PKCS#8 format. It can handle
  97. both unencrypted PKCS#8 PrivateKeyInfo format and EncryptedPrivateKeyInfo
  98. format with a variety of PKCS#5 (v1.5 and v2.0) and PKCS#12 algorithms.
  99. .SH OPTIONS
  100. .IX Header "OPTIONS"
  101. .IP \fB\-help\fR 4
  102. .IX Item "-help"
  103. Print out a usage message.
  104. .IP \fB\-topk8\fR 4
  105. .IX Item "-topk8"
  106. Normally a PKCS#8 private key is expected on input and a private key will be
  107. written to the output file. With the \fB\-topk8\fR option the situation is
  108. reversed: it reads a private key and writes a PKCS#8 format key.
  109. .IP "\fB\-inform\fR \fBDER\fR|\fBPEM\fR, \fB\-outform\fR \fBDER\fR|\fBPEM\fR" 4
  110. .IX Item "-inform DER|PEM, -outform DER|PEM"
  111. The input and formats; the default is \fBPEM\fR.
  112. See \fBopenssl\-format\-options\fR\|(1) for details.
  113. .Sp
  114. If a key is being converted from PKCS#8 form (i.e. the \fB\-topk8\fR option is
  115. not used) then the input file must be in PKCS#8 format. An encrypted
  116. key is expected unless \fB\-nocrypt\fR is included.
  117. .Sp
  118. If \fB\-topk8\fR is not used and \fBPEM\fR mode is set the output file will be an
  119. unencrypted private key in PKCS#8 format. If the \fB\-traditional\fR option is
  120. used then a traditional format private key is written instead.
  121. .Sp
  122. If \fB\-topk8\fR is not used and \fBDER\fR mode is set the output file will be an
  123. unencrypted private key in traditional DER format.
  124. .Sp
  125. If \fB\-topk8\fR is used then any supported private key can be used for the input
  126. file in a format specified by \fB\-inform\fR. The output file will be encrypted
  127. PKCS#8 format using the specified encryption parameters unless \fB\-nocrypt\fR
  128. is included.
  129. .IP \fB\-traditional\fR 4
  130. .IX Item "-traditional"
  131. When this option is present and \fB\-topk8\fR is not a traditional format private
  132. key is written.
  133. .IP "\fB\-in\fR \fIfilename\fR" 4
  134. .IX Item "-in filename"
  135. This specifies the input filename to read a key from or standard input if this
  136. option is not specified. If the key is encrypted a pass phrase will be
  137. prompted for.
  138. .IP "\fB\-passin\fR \fIarg\fR, \fB\-passout\fR \fIarg\fR" 4
  139. .IX Item "-passin arg, -passout arg"
  140. The password source for the input and output file.
  141. For more information about the format of \fBarg\fR
  142. see \fBopenssl\-passphrase\-options\fR\|(1).
  143. .IP "\fB\-out\fR \fIfilename\fR" 4
  144. .IX Item "-out filename"
  145. This specifies the output filename to write a key to or standard output by
  146. default. If any encryption options are set then a pass phrase will be
  147. prompted for. The output filename should \fBnot\fR be the same as the input
  148. filename.
  149. .IP "\fB\-iter\fR \fIcount\fR" 4
  150. .IX Item "-iter count"
  151. When creating new PKCS#8 containers, use a given number of iterations on
  152. the password in deriving the encryption key for the PKCS#8 output.
  153. High values increase the time required to brute-force a PKCS#8 container.
  154. .IP \fB\-noiter\fR 4
  155. .IX Item "-noiter"
  156. When creating new PKCS#8 containers, use 1 as iteration count.
  157. .IP \fB\-nocrypt\fR 4
  158. .IX Item "-nocrypt"
  159. PKCS#8 keys generated or input are normally PKCS#8 EncryptedPrivateKeyInfo
  160. structures using an appropriate password based encryption algorithm. With
  161. this option an unencrypted PrivateKeyInfo structure is expected or output.
  162. This option does not encrypt private keys at all and should only be used
  163. when absolutely necessary. Certain software such as some versions of Java
  164. code signing software used unencrypted private keys.
  165. .IP "\fB\-v2\fR \fIalg\fR" 4
  166. .IX Item "-v2 alg"
  167. This option sets the PKCS#5 v2.0 algorithm.
  168. .Sp
  169. The \fIalg\fR argument is the encryption algorithm to use, valid values include
  170. \&\fBaes128\fR, \fBaes256\fR and \fBdes3\fR. If this option isn't specified then \fBaes256\fR
  171. is used.
  172. .IP "\fB\-v2prf\fR \fIalg\fR" 4
  173. .IX Item "-v2prf alg"
  174. This option sets the PRF algorithm to use with PKCS#5 v2.0. A typical value
  175. value would be \fBhmacWithSHA256\fR. If this option isn't set then the default
  176. for the cipher is used or \fBhmacWithSHA256\fR if there is no default.
  177. .Sp
  178. Some implementations may not support custom PRF algorithms and may require
  179. the \fBhmacWithSHA1\fR option to work.
  180. .IP "\fB\-v1\fR \fIalg\fR" 4
  181. .IX Item "-v1 alg"
  182. This option indicates a PKCS#5 v1.5 or PKCS#12 algorithm should be used. Some
  183. older implementations may not support PKCS#5 v2.0 and may require this option.
  184. If not specified PKCS#5 v2.0 form is used.
  185. .IP \fB\-scrypt\fR 4
  186. .IX Item "-scrypt"
  187. Uses the \fBscrypt\fR algorithm for private key encryption using default
  188. parameters: currently N=16384, r=8 and p=1 and AES in CBC mode with a 256 bit
  189. key. These parameters can be modified using the \fB\-scrypt_N\fR, \fB\-scrypt_r\fR,
  190. \&\fB\-scrypt_p\fR and \fB\-v2\fR options.
  191. .IP "\fB\-scrypt_N\fR \fIN\fR, \fB\-scrypt_r\fR \fIr\fR, \fB\-scrypt_p\fR \fIp\fR" 4
  192. .IX Item "-scrypt_N N, -scrypt_r r, -scrypt_p p"
  193. Sets the scrypt \fIN\fR, \fIr\fR or \fIp\fR parameters.
  194. .IP \fB\-saltlen\fR 4
  195. .IX Item "-saltlen"
  196. Sets the length (in bytes) of the salt to use for the PBE algorithm.
  197. If this value is not specified, the default for PBES2 is 16 (128 bits)
  198. and 8 (64 bits) for PBES1.
  199. .IP "\fB\-rand\fR \fIfiles\fR, \fB\-writerand\fR \fIfile\fR" 4
  200. .IX Item "-rand files, -writerand file"
  201. See "Random State Options" in \fBopenssl\fR\|(1) for details.
  202. .IP "\fB\-engine\fR \fIid\fR" 4
  203. .IX Item "-engine id"
  204. See "Engine Options" in \fBopenssl\fR\|(1).
  205. This option is deprecated.
  206. .IP "\fB\-provider\fR \fIname\fR" 4
  207. .IX Item "-provider name"
  208. .PD 0
  209. .IP "\fB\-provider\-path\fR \fIpath\fR" 4
  210. .IX Item "-provider-path path"
  211. .IP "\fB\-propquery\fR \fIpropq\fR" 4
  212. .IX Item "-propquery propq"
  213. .PD
  214. See "Provider Options" in \fBopenssl\fR\|(1), \fBprovider\fR\|(7), and \fBproperty\fR\|(7).
  215. .SH NOTES
  216. .IX Header "NOTES"
  217. By default, when converting a key to PKCS#8 format, PKCS#5 v2.0 using 256 bit
  218. AES with HMAC and SHA256 is used.
  219. .PP
  220. Some older implementations do not support PKCS#5 v2.0 format and require
  221. the older PKCS#5 v1.5 form instead, possibly also requiring insecure weak
  222. encryption algorithms such as 56 bit DES.
  223. .PP
  224. Private keys encrypted using PKCS#5 v2.0 algorithms and high iteration
  225. counts are more secure that those encrypted using the traditional
  226. SSLeay compatible formats. So if additional security is considered
  227. important the keys should be converted.
  228. .PP
  229. It is possible to write out DER encoded encrypted private keys in
  230. PKCS#8 format because the encryption details are included at an ASN1
  231. level whereas the traditional format includes them at a PEM level.
  232. .SH "PKCS#5 V1.5 AND PKCS#12 ALGORITHMS"
  233. .IX Header "PKCS#5 V1.5 AND PKCS#12 ALGORITHMS"
  234. Various algorithms can be used with the \fB\-v1\fR command line option,
  235. including PKCS#5 v1.5 and PKCS#12. These are described in more detail
  236. below.
  237. .IP "\fBPBE\-MD2\-DES PBE\-MD5\-DES\fR" 4
  238. .IX Item "PBE-MD2-DES PBE-MD5-DES"
  239. These algorithms were included in the original PKCS#5 v1.5 specification.
  240. They only offer 56 bits of protection since they both use DES.
  241. .IP "\fBPBE\-SHA1\-RC2\-64\fR, \fBPBE\-MD2\-RC2\-64\fR, \fBPBE\-MD5\-RC2\-64\fR, \fBPBE\-SHA1\-DES\fR" 4
  242. .IX Item "PBE-SHA1-RC2-64, PBE-MD2-RC2-64, PBE-MD5-RC2-64, PBE-SHA1-DES"
  243. These algorithms are not mentioned in the original PKCS#5 v1.5 specification
  244. but they use the same key derivation algorithm and are supported by some
  245. software. They are mentioned in PKCS#5 v2.0. They use either 64 bit RC2 or
  246. 56 bit DES.
  247. .IP "\fBPBE\-SHA1\-RC4\-128\fR, \fBPBE\-SHA1\-RC4\-40\fR, \fBPBE\-SHA1\-3DES\fR, \fBPBE\-SHA1\-2DES\fR, \fBPBE\-SHA1\-RC2\-128\fR, \fBPBE\-SHA1\-RC2\-40\fR" 4
  248. .IX Item "PBE-SHA1-RC4-128, PBE-SHA1-RC4-40, PBE-SHA1-3DES, PBE-SHA1-2DES, PBE-SHA1-RC2-128, PBE-SHA1-RC2-40"
  249. These algorithms use the PKCS#12 password based encryption algorithm and
  250. allow strong encryption algorithms like triple DES or 128 bit RC2 to be used.
  251. .SH EXAMPLES
  252. .IX Header "EXAMPLES"
  253. Convert a private key to PKCS#8 format using default parameters (AES with
  254. 256 bit key and \fBhmacWithSHA256\fR):
  255. .PP
  256. .Vb 1
  257. \& openssl pkcs8 \-in key.pem \-topk8 \-out enckey.pem
  258. .Ve
  259. .PP
  260. Convert a private key to PKCS#8 unencrypted format:
  261. .PP
  262. .Vb 1
  263. \& openssl pkcs8 \-in key.pem \-topk8 \-nocrypt \-out enckey.pem
  264. .Ve
  265. .PP
  266. Convert a private key to PKCS#5 v2.0 format using triple DES:
  267. .PP
  268. .Vb 1
  269. \& openssl pkcs8 \-in key.pem \-topk8 \-v2 des3 \-out enckey.pem
  270. .Ve
  271. .PP
  272. Convert a private key to PKCS#5 v2.0 format using AES with 256 bits in CBC
  273. mode and \fBhmacWithSHA512\fR PRF:
  274. .PP
  275. .Vb 1
  276. \& openssl pkcs8 \-in key.pem \-topk8 \-v2 aes\-256\-cbc \-v2prf hmacWithSHA512 \-out enckey.pem
  277. .Ve
  278. .PP
  279. Convert a private key to PKCS#8 using a PKCS#5 1.5 compatible algorithm
  280. (DES):
  281. .PP
  282. .Vb 1
  283. \& openssl pkcs8 \-in key.pem \-topk8 \-v1 PBE\-MD5\-DES \-out enckey.pem
  284. .Ve
  285. .PP
  286. Convert a private key to PKCS#8 using a PKCS#12 compatible algorithm
  287. (3DES):
  288. .PP
  289. .Vb 1
  290. \& openssl pkcs8 \-in key.pem \-topk8 \-out enckey.pem \-v1 PBE\-SHA1\-3DES
  291. .Ve
  292. .PP
  293. Read a DER unencrypted PKCS#8 format private key:
  294. .PP
  295. .Vb 1
  296. \& openssl pkcs8 \-inform DER \-nocrypt \-in key.der \-out key.pem
  297. .Ve
  298. .PP
  299. Convert a private key from any PKCS#8 encrypted format to traditional format:
  300. .PP
  301. .Vb 1
  302. \& openssl pkcs8 \-in pk8.pem \-traditional \-out key.pem
  303. .Ve
  304. .PP
  305. Convert a private key to PKCS#8 format, encrypting with AES\-256 and with
  306. one million iterations of the password:
  307. .PP
  308. .Vb 1
  309. \& openssl pkcs8 \-in key.pem \-topk8 \-v2 aes\-256\-cbc \-iter 1000000 \-out pk8.pem
  310. .Ve
  311. .SH STANDARDS
  312. .IX Header "STANDARDS"
  313. Test vectors from this PKCS#5 v2.0 implementation were posted to the
  314. pkcs-tng mailing list using triple DES, DES and RC2 with high iteration
  315. counts, several people confirmed that they could decrypt the private
  316. keys produced and therefore, it can be assumed that the PKCS#5 v2.0
  317. implementation is reasonably accurate at least as far as these
  318. algorithms are concerned.
  319. .PP
  320. The format of PKCS#8 DSA (and other) private keys is not well documented:
  321. it is hidden away in PKCS#11 v2.01, section 11.9. OpenSSL's default DSA
  322. PKCS#8 private key format complies with this standard.
  323. .SH BUGS
  324. .IX Header "BUGS"
  325. There should be an option that prints out the encryption algorithm
  326. in use and other details such as the iteration count.
  327. .SH "SEE ALSO"
  328. .IX Header "SEE ALSO"
  329. \&\fBopenssl\fR\|(1),
  330. \&\fBopenssl\-dsa\fR\|(1),
  331. \&\fBopenssl\-rsa\fR\|(1),
  332. \&\fBopenssl\-genrsa\fR\|(1),
  333. \&\fBopenssl\-gendsa\fR\|(1)
  334. .SH HISTORY
  335. .IX Header "HISTORY"
  336. The \fB\-iter\fR option was added in OpenSSL 1.1.0.
  337. .PP
  338. The \fB\-engine\fR option was deprecated in OpenSSL 3.0.
  339. .SH COPYRIGHT
  340. .IX Header "COPYRIGHT"
  341. Copyright 2000\-2023 The OpenSSL Project Authors. All Rights Reserved.
  342. .PP
  343. Licensed under the Apache License 2.0 (the "License"). You may not use
  344. this file except in compliance with the License. You can obtain a copy
  345. in the file LICENSE in the source distribution or at
  346. <https://www.openssl.org/source/license.html>.