]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - secure/lib/libcrypto/man/PEM_read_bio_PrivateKey.3
Regen amd64 assembly files for OpenSSL 1.1.1.
[FreeBSD/FreeBSD.git] / secure / lib / libcrypto / man / PEM_read_bio_PrivateKey.3
1 .\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
6 .if t .sp .5v
7 .if n .sp
8 ..
9 .de Vb \" Begin verbatim text
10 .ft CW
11 .nf
12 .ne \\$1
13 ..
14 .de Ve \" End verbatim text
15 .ft R
16 .fi
17 ..
18 .\" Set up some character translations and predefined strings.  \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
21 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
24 .tr \(*W-
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26 .ie n \{\
27 .    ds -- \(*W-
28 .    ds PI pi
29 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
31 .    ds L" ""
32 .    ds R" ""
33 .    ds C` ""
34 .    ds C' ""
35 'br\}
36 .el\{\
37 .    ds -- \|\(em\|
38 .    ds PI \(*p
39 .    ds L" ``
40 .    ds R" ''
41 .    ds C`
42 .    ds C'
43 'br\}
44 .\"
45 .\" Escape single quotes in literal strings from groff's Unicode transform.
46 .ie \n(.g .ds Aq \(aq
47 .el       .ds Aq '
48 .\"
49 .\" If the F register is >0, we'll generate index entries on stderr for
50 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
51 .\" entries marked with X<> in POD.  Of course, you'll have to process the
52 .\" output yourself in some meaningful fashion.
53 .\"
54 .\" Avoid warning from groff about undefined register 'F'.
55 .de IX
56 ..
57 .if !\nF .nr F 0
58 .if \nF>0 \{\
59 .    de IX
60 .    tm Index:\\$1\t\\n%\t"\\$2"
61 ..
62 .    if !\nF==2 \{\
63 .        nr % 0
64 .        nr F 2
65 .    \}
66 .\}
67 .\"
68 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
70 .    \" fudge factors for nroff and troff
71 .if n \{\
72 .    ds #H 0
73 .    ds #V .8m
74 .    ds #F .3m
75 .    ds #[ \f1
76 .    ds #] \fP
77 .\}
78 .if t \{\
79 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80 .    ds #V .6m
81 .    ds #F 0
82 .    ds #[ \&
83 .    ds #] \&
84 .\}
85 .    \" simple accents for nroff and troff
86 .if n \{\
87 .    ds ' \&
88 .    ds ` \&
89 .    ds ^ \&
90 .    ds , \&
91 .    ds ~ ~
92 .    ds /
93 .\}
94 .if t \{\
95 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101 .\}
102 .    \" troff and (daisy-wheel) nroff accents
103 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110 .ds ae a\h'-(\w'a'u*4/10)'e
111 .ds Ae A\h'-(\w'A'u*4/10)'E
112 .    \" corrections for vroff
113 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115 .    \" for low resolution devices (crt and lpr)
116 .if \n(.H>23 .if \n(.V>19 \
117 \{\
118 .    ds : e
119 .    ds 8 ss
120 .    ds o a
121 .    ds d- d\h'-1'\(ga
122 .    ds D- D\h'-1'\(hy
123 .    ds th \o'bp'
124 .    ds Th \o'LP'
125 .    ds ae ae
126 .    ds Ae AE
127 .\}
128 .rm #[ #] #H #V #F C
129 .\" ========================================================================
130 .\"
131 .IX Title "PEM_READ_BIO_PRIVATEKEY 3"
132 .TH PEM_READ_BIO_PRIVATEKEY 3 "2018-09-11" "1.1.1" "OpenSSL"
133 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
134 .\" way too many mistakes in technical documents.
135 .if n .ad l
136 .nh
137 .SH "NAME"
138 pem_password_cb, PEM_read_bio_PrivateKey, PEM_read_PrivateKey, PEM_write_bio_PrivateKey, PEM_write_bio_PrivateKey_traditional, PEM_write_PrivateKey, PEM_write_bio_PKCS8PrivateKey, PEM_write_PKCS8PrivateKey, PEM_write_bio_PKCS8PrivateKey_nid, PEM_write_PKCS8PrivateKey_nid, PEM_read_bio_PUBKEY, PEM_read_PUBKEY, PEM_write_bio_PUBKEY, PEM_write_PUBKEY, PEM_read_bio_RSAPrivateKey, PEM_read_RSAPrivateKey, PEM_write_bio_RSAPrivateKey, PEM_write_RSAPrivateKey, PEM_read_bio_RSAPublicKey, PEM_read_RSAPublicKey, PEM_write_bio_RSAPublicKey, PEM_write_RSAPublicKey, PEM_read_bio_RSA_PUBKEY, PEM_read_RSA_PUBKEY, PEM_write_bio_RSA_PUBKEY, PEM_write_RSA_PUBKEY, PEM_read_bio_DSAPrivateKey, PEM_read_DSAPrivateKey, PEM_write_bio_DSAPrivateKey, PEM_write_DSAPrivateKey, PEM_read_bio_DSA_PUBKEY, PEM_read_DSA_PUBKEY, PEM_write_bio_DSA_PUBKEY, PEM_write_DSA_PUBKEY, PEM_read_bio_DSAparams, PEM_read_DSAparams, PEM_write_bio_DSAparams, PEM_write_DSAparams, PEM_read_bio_DHparams, PEM_read_DHparams, PEM_write_bio_DHparams, PEM_write_DHparams, PEM_read_bio_X509, PEM_read_X509, PEM_write_bio_X509, PEM_write_X509, PEM_read_bio_X509_AUX, PEM_read_X509_AUX, PEM_write_bio_X509_AUX, PEM_write_X509_AUX, PEM_read_bio_X509_REQ, PEM_read_X509_REQ, PEM_write_bio_X509_REQ, PEM_write_X509_REQ, PEM_write_bio_X509_REQ_NEW, PEM_write_X509_REQ_NEW, PEM_read_bio_X509_CRL, PEM_read_X509_CRL, PEM_write_bio_X509_CRL, PEM_write_X509_CRL, PEM_read_bio_PKCS7, PEM_read_PKCS7, PEM_write_bio_PKCS7, PEM_write_PKCS7 \- PEM routines
139 .SH "SYNOPSIS"
140 .IX Header "SYNOPSIS"
141 .Vb 1
142 \& #include <openssl/pem.h>
143 \&
144 \& typedef int pem_password_cb(char *buf, int size, int rwflag, void *u);
145 \&
146 \& EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x,
147 \&                                   pem_password_cb *cb, void *u);
148 \& EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x,
149 \&                               pem_password_cb *cb, void *u);
150 \& int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
151 \&                              unsigned char *kstr, int klen,
152 \&                              pem_password_cb *cb, void *u);
153 \& int PEM_write_bio_PrivateKey_traditional(BIO *bp, EVP_PKEY *x,
154 \&                                          const EVP_CIPHER *enc,
155 \&                                          unsigned char *kstr, int klen,
156 \&                                          pem_password_cb *cb, void *u);
157 \& int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
158 \&                          unsigned char *kstr, int klen,
159 \&                          pem_password_cb *cb, void *u);
160 \&
161 \& int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
162 \&                                   char *kstr, int klen,
163 \&                                   pem_password_cb *cb, void *u);
164 \& int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
165 \&                               char *kstr, int klen,
166 \&                               pem_password_cb *cb, void *u);
167 \& int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
168 \&                                       char *kstr, int klen,
169 \&                                       pem_password_cb *cb, void *u);
170 \& int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
171 \&                                   char *kstr, int klen,
172 \&                                   pem_password_cb *cb, void *u);
173 \&
174 \& EVP_PKEY *PEM_read_bio_PUBKEY(BIO *bp, EVP_PKEY **x,
175 \&                               pem_password_cb *cb, void *u);
176 \& EVP_PKEY *PEM_read_PUBKEY(FILE *fp, EVP_PKEY **x,
177 \&                           pem_password_cb *cb, void *u);
178 \& int PEM_write_bio_PUBKEY(BIO *bp, EVP_PKEY *x);
179 \& int PEM_write_PUBKEY(FILE *fp, EVP_PKEY *x);
180 \&
181 \& RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **x,
182 \&                                 pem_password_cb *cb, void *u);
183 \& RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **x,
184 \&                             pem_password_cb *cb, void *u);
185 \& int PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc,
186 \&                                 unsigned char *kstr, int klen,
187 \&                                 pem_password_cb *cb, void *u);
188 \& int PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc,
189 \&                             unsigned char *kstr, int klen,
190 \&                             pem_password_cb *cb, void *u);
191 \&
192 \& RSA *PEM_read_bio_RSAPublicKey(BIO *bp, RSA **x,
193 \&                                pem_password_cb *cb, void *u);
194 \& RSA *PEM_read_RSAPublicKey(FILE *fp, RSA **x,
195 \&                            pem_password_cb *cb, void *u);
196 \& int PEM_write_bio_RSAPublicKey(BIO *bp, RSA *x);
197 \& int PEM_write_RSAPublicKey(FILE *fp, RSA *x);
198 \&
199 \& RSA *PEM_read_bio_RSA_PUBKEY(BIO *bp, RSA **x,
200 \&                              pem_password_cb *cb, void *u);
201 \& RSA *PEM_read_RSA_PUBKEY(FILE *fp, RSA **x,
202 \&                          pem_password_cb *cb, void *u);
203 \& int PEM_write_bio_RSA_PUBKEY(BIO *bp, RSA *x);
204 \& int PEM_write_RSA_PUBKEY(FILE *fp, RSA *x);
205 \&
206 \& DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **x,
207 \&                                 pem_password_cb *cb, void *u);
208 \& DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **x,
209 \&                             pem_password_cb *cb, void *u);
210 \& int PEM_write_bio_DSAPrivateKey(BIO *bp, DSA *x, const EVP_CIPHER *enc,
211 \&                                 unsigned char *kstr, int klen,
212 \&                                 pem_password_cb *cb, void *u);
213 \& int PEM_write_DSAPrivateKey(FILE *fp, DSA *x, const EVP_CIPHER *enc,
214 \&                             unsigned char *kstr, int klen,
215 \&                             pem_password_cb *cb, void *u);
216 \&
217 \& DSA *PEM_read_bio_DSA_PUBKEY(BIO *bp, DSA **x,
218 \&                              pem_password_cb *cb, void *u);
219 \& DSA *PEM_read_DSA_PUBKEY(FILE *fp, DSA **x,
220 \&                          pem_password_cb *cb, void *u);
221 \& int PEM_write_bio_DSA_PUBKEY(BIO *bp, DSA *x);
222 \& int PEM_write_DSA_PUBKEY(FILE *fp, DSA *x);
223 \&
224 \& DSA *PEM_read_bio_DSAparams(BIO *bp, DSA **x, pem_password_cb *cb, void *u);
225 \& DSA *PEM_read_DSAparams(FILE *fp, DSA **x, pem_password_cb *cb, void *u);
226 \& int PEM_write_bio_DSAparams(BIO *bp, DSA *x);
227 \& int PEM_write_DSAparams(FILE *fp, DSA *x);
228 \&
229 \& DH *PEM_read_bio_DHparams(BIO *bp, DH **x, pem_password_cb *cb, void *u);
230 \& DH *PEM_read_DHparams(FILE *fp, DH **x, pem_password_cb *cb, void *u);
231 \& int PEM_write_bio_DHparams(BIO *bp, DH *x);
232 \& int PEM_write_DHparams(FILE *fp, DH *x);
233 \&
234 \& X509 *PEM_read_bio_X509(BIO *bp, X509 **x, pem_password_cb *cb, void *u);
235 \& X509 *PEM_read_X509(FILE *fp, X509 **x, pem_password_cb *cb, void *u);
236 \& int PEM_write_bio_X509(BIO *bp, X509 *x);
237 \& int PEM_write_X509(FILE *fp, X509 *x);
238 \&
239 \& X509 *PEM_read_bio_X509_AUX(BIO *bp, X509 **x, pem_password_cb *cb, void *u);
240 \& X509 *PEM_read_X509_AUX(FILE *fp, X509 **x, pem_password_cb *cb, void *u);
241 \& int PEM_write_bio_X509_AUX(BIO *bp, X509 *x);
242 \& int PEM_write_X509_AUX(FILE *fp, X509 *x);
243 \&
244 \& X509_REQ *PEM_read_bio_X509_REQ(BIO *bp, X509_REQ **x,
245 \&                                 pem_password_cb *cb, void *u);
246 \& X509_REQ *PEM_read_X509_REQ(FILE *fp, X509_REQ **x,
247 \&                             pem_password_cb *cb, void *u);
248 \& int PEM_write_bio_X509_REQ(BIO *bp, X509_REQ *x);
249 \& int PEM_write_X509_REQ(FILE *fp, X509_REQ *x);
250 \& int PEM_write_bio_X509_REQ_NEW(BIO *bp, X509_REQ *x);
251 \& int PEM_write_X509_REQ_NEW(FILE *fp, X509_REQ *x);
252 \&
253 \& X509_CRL *PEM_read_bio_X509_CRL(BIO *bp, X509_CRL **x,
254 \&                                 pem_password_cb *cb, void *u);
255 \& X509_CRL *PEM_read_X509_CRL(FILE *fp, X509_CRL **x,
256 \&                             pem_password_cb *cb, void *u);
257 \& int PEM_write_bio_X509_CRL(BIO *bp, X509_CRL *x);
258 \& int PEM_write_X509_CRL(FILE *fp, X509_CRL *x);
259 \&
260 \& PKCS7 *PEM_read_bio_PKCS7(BIO *bp, PKCS7 **x, pem_password_cb *cb, void *u);
261 \& PKCS7 *PEM_read_PKCS7(FILE *fp, PKCS7 **x, pem_password_cb *cb, void *u);
262 \& int PEM_write_bio_PKCS7(BIO *bp, PKCS7 *x);
263 \& int PEM_write_PKCS7(FILE *fp, PKCS7 *x);
264 .Ve
265 .SH "DESCRIPTION"
266 .IX Header "DESCRIPTION"
267 The \s-1PEM\s0 functions read or write structures in \s-1PEM\s0 format. In
268 this sense \s-1PEM\s0 format is simply base64 encoded data surrounded
269 by header lines.
270 .PP
271 For more details about the meaning of arguments see the
272 \&\fB\s-1PEM FUNCTION ARGUMENTS\s0\fR section.
273 .PP
274 Each operation has four functions associated with it. For
275 brevity the term "\fB\s-1TYPE\s0\fR functions" will be used below to collectively
276 refer to the \fIPEM_read_bio_TYPE()\fR, \fIPEM_read_TYPE()\fR,
277 \&\fIPEM_write_bio_TYPE()\fR, and \fIPEM_write_TYPE()\fR functions.
278 .PP
279 The \fBPrivateKey\fR functions read or write a private key in \s-1PEM\s0 format using an
280 \&\s-1EVP_PKEY\s0 structure. The write routines use PKCS#8 private key format and are
281 equivalent to \fIPEM_write_bio_PKCS8PrivateKey()\fR.The read functions transparently
282 handle traditional and PKCS#8 format encrypted and unencrypted keys.
283 .PP
284 \&\fIPEM_write_bio_PrivateKey_traditional()\fR writes out a private key in the
285 \&\*(L"traditional\*(R" format with a simple private key marker and should only
286 be used for compatibility with legacy programs.
287 .PP
288 \&\fIPEM_write_bio_PKCS8PrivateKey()\fR and \fIPEM_write_PKCS8PrivateKey()\fR write a private
289 key in an \s-1EVP_PKEY\s0 structure in PKCS#8 EncryptedPrivateKeyInfo format using
290 PKCS#5 v2.0 password based encryption algorithms. The \fBcipher\fR argument
291 specifies the encryption algorithm to use: unlike some other \s-1PEM\s0 routines the
292 encryption is applied at the PKCS#8 level and not in the \s-1PEM\s0 headers. If
293 \&\fBcipher\fR is \s-1NULL\s0 then no encryption is used and a PKCS#8 PrivateKeyInfo
294 structure is used instead.
295 .PP
296 \&\fIPEM_write_bio_PKCS8PrivateKey_nid()\fR and \fIPEM_write_PKCS8PrivateKey_nid()\fR
297 also write out a private key as a PKCS#8 EncryptedPrivateKeyInfo however
298 it uses PKCS#5 v1.5 or PKCS#12 encryption algorithms instead. The algorithm
299 to use is specified in the \fBnid\fR parameter and should be the \s-1NID\s0 of the
300 corresponding \s-1OBJECT IDENTIFIER\s0 (see \s-1NOTES\s0 section).
301 .PP
302 The \fB\s-1PUBKEY\s0\fR functions process a public key using an \s-1EVP_PKEY\s0
303 structure. The public key is encoded as a SubjectPublicKeyInfo
304 structure.
305 .PP
306 The \fBRSAPrivateKey\fR functions process an \s-1RSA\s0 private key using an
307 \&\s-1RSA\s0 structure. The write routines uses traditional format. The read
308 routines handles the same formats as the \fBPrivateKey\fR
309 functions but an error occurs if the private key is not \s-1RSA.\s0
310 .PP
311 The \fBRSAPublicKey\fR functions process an \s-1RSA\s0 public key using an
312 \&\s-1RSA\s0 structure. The public key is encoded using a PKCS#1 RSAPublicKey
313 structure.
314 .PP
315 The \fB\s-1RSA_PUBKEY\s0\fR functions also process an \s-1RSA\s0 public key using
316 an \s-1RSA\s0 structure. However the public key is encoded using a
317 SubjectPublicKeyInfo structure and an error occurs if the public
318 key is not \s-1RSA.\s0
319 .PP
320 The \fBDSAPrivateKey\fR functions process a \s-1DSA\s0 private key using a
321 \&\s-1DSA\s0 structure. The write routines uses traditional format. The read
322 routines handles the same formats as the \fBPrivateKey\fR
323 functions but an error occurs if the private key is not \s-1DSA.\s0
324 .PP
325 The \fB\s-1DSA_PUBKEY\s0\fR functions process a \s-1DSA\s0 public key using
326 a \s-1DSA\s0 structure. The public key is encoded using a
327 SubjectPublicKeyInfo structure and an error occurs if the public
328 key is not \s-1DSA.\s0
329 .PP
330 The \fBDSAparams\fR functions process \s-1DSA\s0 parameters using a \s-1DSA\s0
331 structure. The parameters are encoded using a Dss-Parms structure
332 as defined in \s-1RFC2459.\s0
333 .PP
334 The \fBDHparams\fR functions process \s-1DH\s0 parameters using a \s-1DH\s0
335 structure. The parameters are encoded using a PKCS#3 DHparameter
336 structure.
337 .PP
338 The \fBX509\fR functions process an X509 certificate using an X509
339 structure. They will also process a trusted X509 certificate but
340 any trust settings are discarded.
341 .PP
342 The \fBX509_AUX\fR functions process a trusted X509 certificate using
343 an X509 structure.
344 .PP
345 The \fBX509_REQ\fR and \fBX509_REQ_NEW\fR functions process a PKCS#10
346 certificate request using an X509_REQ structure. The \fBX509_REQ\fR
347 write functions use \fB\s-1CERTIFICATE REQUEST\s0\fR in the header whereas
348 the \fBX509_REQ_NEW\fR functions use \fB\s-1NEW CERTIFICATE REQUEST\s0\fR
349 (as required by some CAs). The \fBX509_REQ\fR read functions will
350 handle either form so there are no \fBX509_REQ_NEW\fR read functions.
351 .PP
352 The \fBX509_CRL\fR functions process an X509 \s-1CRL\s0 using an X509_CRL
353 structure.
354 .PP
355 The \fB\s-1PKCS7\s0\fR functions process a PKCS#7 ContentInfo using a \s-1PKCS7\s0
356 structure.
357 .SH "PEM FUNCTION ARGUMENTS"
358 .IX Header "PEM FUNCTION ARGUMENTS"
359 The \s-1PEM\s0 functions have many common arguments.
360 .PP
361 The \fBbp\fR \s-1BIO\s0 parameter (if present) specifies the \s-1BIO\s0 to read from
362 or write to.
363 .PP
364 The \fBfp\fR \s-1FILE\s0 parameter (if present) specifies the \s-1FILE\s0 pointer to
365 read from or write to.
366 .PP
367 The \s-1PEM\s0 read functions all take an argument \fB\s-1TYPE\s0 **x\fR and return
368 a \fB\s-1TYPE\s0 *\fR pointer. Where \fB\s-1TYPE\s0\fR is whatever structure the function
369 uses. If \fBx\fR is \s-1NULL\s0 then the parameter is ignored. If \fBx\fR is not
370 \&\s-1NULL\s0 but \fB*x\fR is \s-1NULL\s0 then the structure returned will be written
371 to \fB*x\fR. If neither \fBx\fR nor \fB*x\fR is \s-1NULL\s0 then an attempt is made
372 to reuse the structure at \fB*x\fR (but see \s-1BUGS\s0 and \s-1EXAMPLES\s0 sections).
373 Irrespective of the value of \fBx\fR a pointer to the structure is always
374 returned (or \s-1NULL\s0 if an error occurred).
375 .PP
376 The \s-1PEM\s0 functions which write private keys take an \fBenc\fR parameter
377 which specifies the encryption algorithm to use, encryption is done
378 at the \s-1PEM\s0 level. If this parameter is set to \s-1NULL\s0 then the private
379 key is written in unencrypted form.
380 .PP
381 The \fBcb\fR argument is the callback to use when querying for the pass
382 phrase used for encrypted \s-1PEM\s0 structures (normally only private keys).
383 .PP
384 For the \s-1PEM\s0 write routines if the \fBkstr\fR parameter is not \s-1NULL\s0 then
385 \&\fBklen\fR bytes at \fBkstr\fR are used as the passphrase and \fBcb\fR is
386 ignored.
387 .PP
388 If the \fBcb\fR parameters is set to \s-1NULL\s0 and the \fBu\fR parameter is not
389 \&\s-1NULL\s0 then the \fBu\fR parameter is interpreted as a null terminated string
390 to use as the passphrase. If both \fBcb\fR and \fBu\fR are \s-1NULL\s0 then the
391 default callback routine is used which will typically prompt for the
392 passphrase on the current terminal with echoing turned off.
393 .PP
394 The default passphrase callback is sometimes inappropriate (for example
395 in a \s-1GUI\s0 application) so an alternative can be supplied. The callback
396 routine has the following form:
397 .PP
398 .Vb 1
399 \& int cb(char *buf, int size, int rwflag, void *u);
400 .Ve
401 .PP
402 \&\fBbuf\fR is the buffer to write the passphrase to. \fBsize\fR is the maximum
403 length of the passphrase (i.e. the size of buf). \fBrwflag\fR is a flag
404 which is set to 0 when reading and 1 when writing. A typical routine
405 will ask the user to verify the passphrase (for example by prompting
406 for it twice) if \fBrwflag\fR is 1. The \fBu\fR parameter has the same
407 value as the \fBu\fR parameter passed to the \s-1PEM\s0 routine. It allows
408 arbitrary data to be passed to the callback by the application
409 (for example a window handle in a \s-1GUI\s0 application). The callback
410 \&\fBmust\fR return the number of characters in the passphrase or \-1 if
411 an error occurred.
412 .SH "EXAMPLES"
413 .IX Header "EXAMPLES"
414 Although the \s-1PEM\s0 routines take several arguments in almost all applications
415 most of them are set to 0 or \s-1NULL.\s0
416 .PP
417 Read a certificate in \s-1PEM\s0 format from a \s-1BIO:\s0
418 .PP
419 .Vb 1
420 \& X509 *x;
421 \&
422 \& x = PEM_read_bio_X509(bp, NULL, 0, NULL);
423 \& if (x == NULL)
424 \&     /* Error */
425 .Ve
426 .PP
427 Alternative method:
428 .PP
429 .Vb 1
430 \& X509 *x = NULL;
431 \&
432 \& if (!PEM_read_bio_X509(bp, &x, 0, NULL))
433 \&     /* Error */
434 .Ve
435 .PP
436 Write a certificate to a \s-1BIO:\s0
437 .PP
438 .Vb 2
439 \& if (!PEM_write_bio_X509(bp, x))
440 \&     /* Error */
441 .Ve
442 .PP
443 Write a private key (using traditional format) to a \s-1BIO\s0 using
444 triple \s-1DES\s0 encryption, the pass phrase is prompted for:
445 .PP
446 .Vb 2
447 \& if (!PEM_write_bio_PrivateKey(bp, key, EVP_des_ede3_cbc(), NULL, 0, 0, NULL))
448 \&     /* Error */
449 .Ve
450 .PP
451 Write a private key (using PKCS#8 format) to a \s-1BIO\s0 using triple
452 \&\s-1DES\s0 encryption, using the pass phrase \*(L"hello\*(R":
453 .PP
454 .Vb 3
455 \& if (!PEM_write_bio_PKCS8PrivateKey(bp, key, EVP_des_ede3_cbc(),
456 \&                                    NULL, 0, 0, "hello"))
457 \&     /* Error */
458 .Ve
459 .PP
460 Read a private key from a \s-1BIO\s0 using a pass phrase callback:
461 .PP
462 .Vb 3
463 \& key = PEM_read_bio_PrivateKey(bp, NULL, pass_cb, "My Private Key");
464 \& if (key == NULL)
465 \&     /* Error */
466 .Ve
467 .PP
468 Skeleton pass phrase callback:
469 .PP
470 .Vb 2
471 \& int pass_cb(char *buf, int size, int rwflag, void *u)
472 \& {
473 \&
474 \&     /* We\*(Aqd probably do something else if \*(Aqrwflag\*(Aq is 1 */
475 \&     printf("Enter pass phrase for \e"%s\e"\en", (char *)u);
476 \&
477 \&     /* get pass phrase, length \*(Aqlen\*(Aq into \*(Aqtmp\*(Aq */
478 \&     char *tmp = "hello";
479 \&     if (tmp == NULL) /* An error occurred */
480 \&         return \-1;
481 \&
482 \&     size_t len = strlen(tmp);
483 \&
484 \&     if (len > size)
485 \&         len = size;
486 \&     memcpy(buf, tmp, len);
487 \&     return len;
488 \& }
489 .Ve
490 .SH "NOTES"
491 .IX Header "NOTES"
492 The old \fBPrivateKey\fR write routines are retained for compatibility.
493 New applications should write private keys using the
494 \&\fIPEM_write_bio_PKCS8PrivateKey()\fR or \fIPEM_write_PKCS8PrivateKey()\fR routines
495 because they are more secure (they use an iteration count of 2048 whereas
496 the traditional routines use a count of 1) unless compatibility with older
497 versions of OpenSSL is important.
498 .PP
499 The \fBPrivateKey\fR read routines can be used in all applications because
500 they handle all formats transparently.
501 .PP
502 A frequent cause of problems is attempting to use the \s-1PEM\s0 routines like
503 this:
504 .PP
505 .Vb 1
506 \& X509 *x;
507 \&
508 \& PEM_read_bio_X509(bp, &x, 0, NULL);
509 .Ve
510 .PP
511 this is a bug because an attempt will be made to reuse the data at \fBx\fR
512 which is an uninitialised pointer.
513 .PP
514 These functions make no assumption regarding the pass phrase received from the
515 password callback.
516 It will simply be treated as a byte sequence.
517 .SH "PEM ENCRYPTION FORMAT"
518 .IX Header "PEM ENCRYPTION FORMAT"
519 These old \fBPrivateKey\fR routines use a non standard technique for encryption.
520 .PP
521 The private key (or other data) takes the following form:
522 .PP
523 .Vb 3
524 \& \-\-\-\-\-BEGIN RSA PRIVATE KEY\-\-\-\-\-
525 \& Proc\-Type: 4,ENCRYPTED
526 \& DEK\-Info: DES\-EDE3\-CBC,3F17F5316E2BAC89
527 \&
528 \& ...base64 encoded data...
529 \& \-\-\-\-\-END RSA PRIVATE KEY\-\-\-\-\-
530 .Ve
531 .PP
532 The line beginning with \fIProc-Type\fR contains the version and the
533 protection on the encapsulated data. The line beginning \fIDEK-Info\fR
534 contains two comma separated values: the encryption algorithm name as
535 used by \fIEVP_get_cipherbyname()\fR and an initialization vector used by the
536 cipher encoded as a set of hexadecimal digits. After those two lines is
537 the base64\-encoded encrypted data.
538 .PP
539 The encryption key is derived using \fIEVP_BytesToKey()\fR. The cipher's
540 initialization vector is passed to \fIEVP_BytesToKey()\fR as the \fBsalt\fR
541 parameter. Internally, \fB\s-1PKCS5_SALT_LEN\s0\fR bytes of the salt are used
542 (regardless of the size of the initialization vector). The user's
543 password is passed to \fIEVP_BytesToKey()\fR using the \fBdata\fR and \fBdatal\fR
544 parameters. Finally, the library uses an iteration count of 1 for
545 \&\fIEVP_BytesToKey()\fR.
546 .PP
547 The \fBkey\fR derived by \fIEVP_BytesToKey()\fR along with the original initialization
548 vector is then used to decrypt the encrypted data. The \fBiv\fR produced by
549 \&\fIEVP_BytesToKey()\fR is not utilized or needed, and \s-1NULL\s0 should be passed to
550 the function.
551 .PP
552 The pseudo code to derive the key would look similar to:
553 .PP
554 .Vb 2
555 \& EVP_CIPHER* cipher = EVP_des_ede3_cbc();
556 \& EVP_MD* md = EVP_md5();
557 \&
558 \& unsigned int nkey = EVP_CIPHER_key_length(cipher);
559 \& unsigned int niv = EVP_CIPHER_iv_length(cipher);
560 \& unsigned char key[nkey];
561 \& unsigned char iv[niv];
562 \&
563 \& memcpy(iv, HexToBin("3F17F5316E2BAC89"), niv);
564 \& rc = EVP_BytesToKey(cipher, md, iv /*salt*/, pword, plen, 1, key, NULL /*iv*/);
565 \& if (rc != nkey)
566 \&     /* Error */
567 \&
568 \& /* On success, use key and iv to initialize the cipher */
569 .Ve
570 .SH "BUGS"
571 .IX Header "BUGS"
572 The \s-1PEM\s0 read routines in some versions of OpenSSL will not correctly reuse
573 an existing structure. Therefore the following:
574 .PP
575 .Vb 1
576 \& PEM_read_bio_X509(bp, &x, 0, NULL);
577 .Ve
578 .PP
579 where \fBx\fR already contains a valid certificate, may not work, whereas:
580 .PP
581 .Vb 2
582 \& X509_free(x);
583 \& x = PEM_read_bio_X509(bp, NULL, 0, NULL);
584 .Ve
585 .PP
586 is guaranteed to work.
587 .SH "RETURN VALUES"
588 .IX Header "RETURN VALUES"
589 The read routines return either a pointer to the structure read or \s-1NULL\s0
590 if an error occurred.
591 .PP
592 The write routines return 1 for success or 0 for failure.
593 .SH "HISTORY"
594 .IX Header "HISTORY"
595 The old Netscape certificate sequences were no longer documented
596 in OpenSSL 1.1.0; applications should use the \s-1PKCS7\s0 standard instead
597 as they will be formally deprecated in a future releases.
598 .SH "SEE ALSO"
599 .IX Header "SEE ALSO"
600 \&\fIEVP_EncryptInit\fR\|(3), \fIEVP_BytesToKey\fR\|(3),
601 \&\fIpassphrase\-encoding\fR\|(7)
602 .SH "COPYRIGHT"
603 .IX Header "COPYRIGHT"
604 Copyright 2001\-2018 The OpenSSL Project Authors. All Rights Reserved.
605 .PP
606 Licensed under the OpenSSL license (the \*(L"License\*(R").  You may not use
607 this file except in compliance with the License.  You can obtain a copy
608 in the file \s-1LICENSE\s0 in the source distribution or at
609 <https://www.openssl.org/source/license.html>.