Sync usage with man page.
[netbsd-mini2440.git] / crypto / external / bsd / openssl / lib / libcrypto / man / openssl_pem.3
blob75f6b371fe8b1349d606dd8414042a8dc0072d77
1 .\"     $NetBSD: libcrypto.pl,v 1.3 2007/11/27 22:16:03 christos Exp $
2 .\"
3 .\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05)
4 .\"
5 .\" Standard preamble:
6 .\" ========================================================================
7 .de Sh \" Subsection heading
8 .br
9 .if t .Sp
10 .ne 5
11 .PP
12 \fB\\$1\fR
13 .PP
15 .de Sp \" Vertical space (when we can't use .PP)
16 .if t .sp .5v
17 .if n .sp
19 .de Vb \" Begin verbatim text
20 .ft CW
21 .nf
22 .ne \\$1
24 .de Ve \" End verbatim text
25 .ft R
26 .fi
28 .\" Set up some character translations and predefined strings.  \*(-- will
29 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
30 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
31 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
32 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
33 .\" nothing in troff, for use with C<>.
34 .tr \(*W-
35 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
36 .ie n \{\
37 .    ds -- \(*W-
38 .    ds PI pi
39 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
40 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
41 .    ds L" ""
42 .    ds R" ""
43 .    ds C` ""
44 .    ds C' ""
45 'br\}
46 .el\{\
47 .    ds -- \|\(em\|
48 .    ds PI \(*p
49 .    ds L" ``
50 .    ds R" ''
51 'br\}
52 .\"
53 .\" Escape single quotes in literal strings from groff's Unicode transform.
54 .ie \n(.g .ds Aq \(aq
55 .el       .ds Aq '
56 .\"
57 .\" If the F register is turned on, we'll generate index entries on stderr for
58 .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
59 .\" entries marked with X<> in POD.  Of course, you'll have to process the
60 .\" output yourself in some meaningful fashion.
61 .ie \nF \{\
62 .    de IX
63 .    tm Index:\\$1\t\\n%\t"\\$2"
65 .    nr % 0
66 .    rr F
67 .\}
68 .el \{\
69 .    de IX
71 .\}
72 .\"
73 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
74 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
75 .    \" fudge factors for nroff and troff
76 .if n \{\
77 .    ds #H 0
78 .    ds #V .8m
79 .    ds #F .3m
80 .    ds #[ \f1
81 .    ds #] \fP
82 .\}
83 .if t \{\
84 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
85 .    ds #V .6m
86 .    ds #F 0
87 .    ds #[ \&
88 .    ds #] \&
89 .\}
90 .    \" simple accents for nroff and troff
91 .if n \{\
92 .    ds ' \&
93 .    ds ` \&
94 .    ds ^ \&
95 .    ds , \&
96 .    ds ~ ~
97 .    ds /
98 .\}
99 .if t \{\
100 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
101 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
102 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
103 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
104 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
105 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
107 .    \" troff and (daisy-wheel) nroff accents
108 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
109 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
110 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
111 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
112 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
113 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
114 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
115 .ds ae a\h'-(\w'a'u*4/10)'e
116 .ds Ae A\h'-(\w'A'u*4/10)'E
117 .    \" corrections for vroff
118 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
119 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
120 .    \" for low resolution devices (crt and lpr)
121 .if \n(.H>23 .if \n(.V>19 \
123 .    ds : e
124 .    ds 8 ss
125 .    ds o a
126 .    ds d- d\h'-1'\(ga
127 .    ds D- D\h'-1'\(hy
128 .    ds th \o'bp'
129 .    ds Th \o'LP'
130 .    ds ae ae
131 .    ds Ae AE
133 .rm #[ #] #H #V #F C
134 .\" ========================================================================
136 .IX Title "pem 3"
137 .TH pem 3 "2009-06-02" "1.1.0-dev" "OpenSSL"
138 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
139 .\" way too many mistakes in technical documents.
140 .if n .ad l
142 .SH "NAME"
143 PEM, PEM_read_bio_PrivateKey, PEM_read_PrivateKey, PEM_write_bio_PrivateKey, 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_read_bio_NETSCAPE_CERT_SEQUENCE, PEM_read_NETSCAPE_CERT_SEQUENCE, PEM_write_bio_NETSCAPE_CERT_SEQUENCE, PEM_write_NETSCAPE_CERT_SEQUENCE \- PEM routines
144 .SH "LIBRARY"
145 libcrypto, -lcrypto
146 .SH "SYNOPSIS"
147 .IX Header "SYNOPSIS"
148 .Vb 1
149 \& #include <openssl/pem.h>
151 \& EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x,
152 \&                                        pem_password_cb *cb, void *u);
154 \& EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x,
155 \&                                        pem_password_cb *cb, void *u);
157 \& int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
158 \&                                        unsigned char *kstr, int klen,
159 \&                                        pem_password_cb *cb, void *u);
161 \& int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
162 \&                                        unsigned char *kstr, int klen,
163 \&                                        pem_password_cb *cb, void *u);
165 \& int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
166 \&                                        char *kstr, int klen,
167 \&                                        pem_password_cb *cb, void *u);
169 \& int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
170 \&                                        char *kstr, int klen,
171 \&                                        pem_password_cb *cb, void *u);
173 \& int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
174 \&                                        char *kstr, int klen,
175 \&                                        pem_password_cb *cb, void *u);
177 \& int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
178 \&                                        char *kstr, int klen,
179 \&                                        pem_password_cb *cb, void *u);
181 \& EVP_PKEY *PEM_read_bio_PUBKEY(BIO *bp, EVP_PKEY **x,
182 \&                                        pem_password_cb *cb, void *u);
184 \& EVP_PKEY *PEM_read_PUBKEY(FILE *fp, EVP_PKEY **x,
185 \&                                        pem_password_cb *cb, void *u);
187 \& int PEM_write_bio_PUBKEY(BIO *bp, EVP_PKEY *x);
188 \& int PEM_write_PUBKEY(FILE *fp, EVP_PKEY *x);
190 \& RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **x,
191 \&                                        pem_password_cb *cb, void *u);
193 \& RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **x,
194 \&                                        pem_password_cb *cb, void *u);
196 \& int PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc,
197 \&                                        unsigned char *kstr, int klen,
198 \&                                        pem_password_cb *cb, void *u);
200 \& int PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc,
201 \&                                        unsigned char *kstr, int klen,
202 \&                                        pem_password_cb *cb, void *u);
204 \& RSA *PEM_read_bio_RSAPublicKey(BIO *bp, RSA **x,
205 \&                                        pem_password_cb *cb, void *u);
207 \& RSA *PEM_read_RSAPublicKey(FILE *fp, RSA **x,
208 \&                                        pem_password_cb *cb, void *u);
210 \& int PEM_write_bio_RSAPublicKey(BIO *bp, RSA *x);
212 \& int PEM_write_RSAPublicKey(FILE *fp, RSA *x);
214 \& RSA *PEM_read_bio_RSA_PUBKEY(BIO *bp, RSA **x,
215 \&                                        pem_password_cb *cb, void *u);
217 \& RSA *PEM_read_RSA_PUBKEY(FILE *fp, RSA **x,
218 \&                                        pem_password_cb *cb, void *u);
220 \& int PEM_write_bio_RSA_PUBKEY(BIO *bp, RSA *x);
222 \& int PEM_write_RSA_PUBKEY(FILE *fp, RSA *x);
224 \& DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **x,
225 \&                                        pem_password_cb *cb, void *u);
227 \& DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **x,
228 \&                                        pem_password_cb *cb, void *u);
230 \& int PEM_write_bio_DSAPrivateKey(BIO *bp, DSA *x, const EVP_CIPHER *enc,
231 \&                                        unsigned char *kstr, int klen,
232 \&                                        pem_password_cb *cb, void *u);
234 \& int PEM_write_DSAPrivateKey(FILE *fp, DSA *x, const EVP_CIPHER *enc,
235 \&                                        unsigned char *kstr, int klen,
236 \&                                        pem_password_cb *cb, void *u);
238 \& DSA *PEM_read_bio_DSA_PUBKEY(BIO *bp, DSA **x,
239 \&                                        pem_password_cb *cb, void *u);
241 \& DSA *PEM_read_DSA_PUBKEY(FILE *fp, DSA **x,
242 \&                                        pem_password_cb *cb, void *u);
244 \& int PEM_write_bio_DSA_PUBKEY(BIO *bp, DSA *x);
246 \& int PEM_write_DSA_PUBKEY(FILE *fp, DSA *x);
248 \& DSA *PEM_read_bio_DSAparams(BIO *bp, DSA **x, pem_password_cb *cb, void *u);
250 \& DSA *PEM_read_DSAparams(FILE *fp, DSA **x, pem_password_cb *cb, void *u);
252 \& int PEM_write_bio_DSAparams(BIO *bp, DSA *x);
254 \& int PEM_write_DSAparams(FILE *fp, DSA *x);
256 \& DH *PEM_read_bio_DHparams(BIO *bp, DH **x, pem_password_cb *cb, void *u);
258 \& DH *PEM_read_DHparams(FILE *fp, DH **x, pem_password_cb *cb, void *u);
260 \& int PEM_write_bio_DHparams(BIO *bp, DH *x);
262 \& int PEM_write_DHparams(FILE *fp, DH *x);
264 \& X509 *PEM_read_bio_X509(BIO *bp, X509 **x, pem_password_cb *cb, void *u);
266 \& X509 *PEM_read_X509(FILE *fp, X509 **x, pem_password_cb *cb, void *u);
268 \& int PEM_write_bio_X509(BIO *bp, X509 *x);
270 \& int PEM_write_X509(FILE *fp, X509 *x);
272 \& X509 *PEM_read_bio_X509_AUX(BIO *bp, X509 **x, pem_password_cb *cb, void *u);
274 \& X509 *PEM_read_X509_AUX(FILE *fp, X509 **x, pem_password_cb *cb, void *u);
276 \& int PEM_write_bio_X509_AUX(BIO *bp, X509 *x);
278 \& int PEM_write_X509_AUX(FILE *fp, X509 *x);
280 \& X509_REQ *PEM_read_bio_X509_REQ(BIO *bp, X509_REQ **x,
281 \&                                        pem_password_cb *cb, void *u);
283 \& X509_REQ *PEM_read_X509_REQ(FILE *fp, X509_REQ **x,
284 \&                                        pem_password_cb *cb, void *u);
286 \& int PEM_write_bio_X509_REQ(BIO *bp, X509_REQ *x);
288 \& int PEM_write_X509_REQ(FILE *fp, X509_REQ *x);
290 \& int PEM_write_bio_X509_REQ_NEW(BIO *bp, X509_REQ *x);
292 \& int PEM_write_X509_REQ_NEW(FILE *fp, X509_REQ *x);
294 \& X509_CRL *PEM_read_bio_X509_CRL(BIO *bp, X509_CRL **x,
295 \&                                        pem_password_cb *cb, void *u);
296 \& X509_CRL *PEM_read_X509_CRL(FILE *fp, X509_CRL **x,
297 \&                                        pem_password_cb *cb, void *u);
298 \& int PEM_write_bio_X509_CRL(BIO *bp, X509_CRL *x);
299 \& int PEM_write_X509_CRL(FILE *fp, X509_CRL *x);
301 \& PKCS7 *PEM_read_bio_PKCS7(BIO *bp, PKCS7 **x, pem_password_cb *cb, void *u);
303 \& PKCS7 *PEM_read_PKCS7(FILE *fp, PKCS7 **x, pem_password_cb *cb, void *u);
305 \& int PEM_write_bio_PKCS7(BIO *bp, PKCS7 *x);
307 \& int PEM_write_PKCS7(FILE *fp, PKCS7 *x);
309 \& NETSCAPE_CERT_SEQUENCE *PEM_read_bio_NETSCAPE_CERT_SEQUENCE(BIO *bp,
310 \&                                                NETSCAPE_CERT_SEQUENCE **x,
311 \&                                                pem_password_cb *cb, void *u);
313 \& NETSCAPE_CERT_SEQUENCE *PEM_read_NETSCAPE_CERT_SEQUENCE(FILE *fp,
314 \&                                                NETSCAPE_CERT_SEQUENCE **x,
315 \&                                                pem_password_cb *cb, void *u);
317 \& int PEM_write_bio_NETSCAPE_CERT_SEQUENCE(BIO *bp, NETSCAPE_CERT_SEQUENCE *x);
319 \& int PEM_write_NETSCAPE_CERT_SEQUENCE(FILE *fp, NETSCAPE_CERT_SEQUENCE *x);
321 .SH "DESCRIPTION"
322 .IX Header "DESCRIPTION"
323 The \s-1PEM\s0 functions read or write structures in \s-1PEM\s0 format. In
324 this sense \s-1PEM\s0 format is simply base64 encoded data surrounded
325 by header lines.
327 For more details about the meaning of arguments see the
328 \&\fB\s-1PEM\s0 \s-1FUNCTION\s0 \s-1ARGUMENTS\s0\fR section.
330 Each operation has four functions associated with it. For
331 clarity the term "\fBfoobar\fR functions" will be used to collectively
332 refer to the \fIPEM_read_bio_foobar()\fR, \fIPEM_read_foobar()\fR,
333 \&\fIPEM_write_bio_foobar()\fR and \fIPEM_write_foobar()\fR functions.
335 The \fBPrivateKey\fR functions read or write a private key in
336 \&\s-1PEM\s0 format using an \s-1EVP_PKEY\s0 structure. The write routines use
337 \&\*(L"traditional\*(R" private key format and can handle both \s-1RSA\s0 and \s-1DSA\s0
338 private keys. The read functions can additionally transparently
339 handle PKCS#8 format encrypted and unencrypted keys too.
341 \&\fIPEM_write_bio_PKCS8PrivateKey()\fR and \fIPEM_write_PKCS8PrivateKey()\fR
342 write a private key in an \s-1EVP_PKEY\s0 structure in PKCS#8
343 EncryptedPrivateKeyInfo format using PKCS#5 v2.0 password based encryption
344 algorithms. The \fBcipher\fR argument specifies the encryption algoritm to
345 use: unlike all other \s-1PEM\s0 routines the encryption is applied at the
346 PKCS#8 level and not in the \s-1PEM\s0 headers. If \fBcipher\fR is \s-1NULL\s0 then no
347 encryption is used and a PKCS#8 PrivateKeyInfo structure is used instead.
349 \&\fIPEM_write_bio_PKCS8PrivateKey_nid()\fR and \fIPEM_write_PKCS8PrivateKey_nid()\fR
350 also write out a private key as a PKCS#8 EncryptedPrivateKeyInfo however
351 it uses PKCS#5 v1.5 or PKCS#12 encryption algorithms instead. The algorithm
352 to use is specified in the \fBnid\fR parameter and should be the \s-1NID\s0 of the
353 corresponding \s-1OBJECT\s0 \s-1IDENTIFIER\s0 (see \s-1NOTES\s0 section).
355 The \fB\s-1PUBKEY\s0\fR functions process a public key using an \s-1EVP_PKEY\s0
356 structure. The public key is encoded as a SubjectPublicKeyInfo
357 structure.
359 The \fBRSAPrivateKey\fR functions process an \s-1RSA\s0 private key using an
360 \&\s-1RSA\s0 structure. It handles the same formats as the \fBPrivateKey\fR
361 functions but an error occurs if the private key is not \s-1RSA\s0.
363 The \fBRSAPublicKey\fR functions process an \s-1RSA\s0 public key using an
364 \&\s-1RSA\s0 structure. The public key is encoded using a PKCS#1 RSAPublicKey
365 structure.
367 The \fB\s-1RSA_PUBKEY\s0\fR functions also process an \s-1RSA\s0 public key using
368 an \s-1RSA\s0 structure. However the public key is encoded using a
369 SubjectPublicKeyInfo structure and an error occurs if the public
370 key is not \s-1RSA\s0.
372 The \fBDSAPrivateKey\fR functions process a \s-1DSA\s0 private key using a
373 \&\s-1DSA\s0 structure. It handles the same formats as the \fBPrivateKey\fR
374 functions but an error occurs if the private key is not \s-1DSA\s0.
376 The \fB\s-1DSA_PUBKEY\s0\fR functions process a \s-1DSA\s0 public key using
377 a \s-1DSA\s0 structure. The public key is encoded using a
378 SubjectPublicKeyInfo structure and an error occurs if the public
379 key is not \s-1DSA\s0.
381 The \fBDSAparams\fR functions process \s-1DSA\s0 parameters using a \s-1DSA\s0
382 structure. The parameters are encoded using a foobar structure.
384 The \fBDHparams\fR functions process \s-1DH\s0 parameters using a \s-1DH\s0
385 structure. The parameters are encoded using a PKCS#3 DHparameter
386 structure.
388 The \fBX509\fR functions process an X509 certificate using an X509
389 structure. They will also process a trusted X509 certificate but
390 any trust settings are discarded.
392 The \fBX509_AUX\fR functions process a trusted X509 certificate using
393 an X509 structure.
395 The \fBX509_REQ\fR and \fBX509_REQ_NEW\fR functions process a PKCS#10
396 certificate request using an X509_REQ structure. The \fBX509_REQ\fR
397 write functions use \fB\s-1CERTIFICATE\s0 \s-1REQUEST\s0\fR in the header whereas
398 the \fBX509_REQ_NEW\fR functions use \fB\s-1NEW\s0 \s-1CERTIFICATE\s0 \s-1REQUEST\s0\fR
399 (as required by some CAs). The \fBX509_REQ\fR read functions will
400 handle either form so there are no \fBX509_REQ_NEW\fR read functions.
402 The \fBX509_CRL\fR functions process an X509 \s-1CRL\s0 using an X509_CRL
403 structure.
405 The \fB\s-1PKCS7\s0\fR functions process a PKCS#7 ContentInfo using a \s-1PKCS7\s0
406 structure.
408 The \fB\s-1NETSCAPE_CERT_SEQUENCE\s0\fR functions process a Netscape Certificate
409 Sequence using a \s-1NETSCAPE_CERT_SEQUENCE\s0 structure.
410 .SH "PEM FUNCTION ARGUMENTS"
411 .IX Header "PEM FUNCTION ARGUMENTS"
412 The \s-1PEM\s0 functions have many common arguments.
414 The \fBbp\fR \s-1BIO\s0 parameter (if present) specifies the \s-1BIO\s0 to read from
415 or write to.
417 The \fBfp\fR \s-1FILE\s0 parameter (if present) specifies the \s-1FILE\s0 pointer to
418 read from or write to.
420 The \s-1PEM\s0 read functions all take an argument \fB\s-1TYPE\s0 **x\fR and return
421 a \fB\s-1TYPE\s0 *\fR pointer. Where \fB\s-1TYPE\s0\fR is whatever structure the function
422 uses. If \fBx\fR is \s-1NULL\s0 then the parameter is ignored. If \fBx\fR is not
423 \&\s-1NULL\s0 but \fB*x\fR is \s-1NULL\s0 then the structure returned will be written
424 to \fB*x\fR. If neither \fBx\fR nor \fB*x\fR is \s-1NULL\s0 then an attempt is made
425 to reuse the structure at \fB*x\fR (but see \s-1BUGS\s0 and \s-1EXAMPLES\s0 sections).
426 Irrespective of the value of \fBx\fR a pointer to the structure is always
427 returned (or \s-1NULL\s0 if an error occurred).
429 The \s-1PEM\s0 functions which write private keys take an \fBenc\fR parameter
430 which specifies the encryption algorithm to use, encryption is done
431 at the \s-1PEM\s0 level. If this parameter is set to \s-1NULL\s0 then the private
432 key is written in unencrypted form.
434 The \fBcb\fR argument is the callback to use when querying for the pass
435 phrase used for encrypted \s-1PEM\s0 structures (normally only private keys).
437 For the \s-1PEM\s0 write routines if the \fBkstr\fR parameter is not \s-1NULL\s0 then
438 \&\fBklen\fR bytes at \fBkstr\fR are used as the passphrase and \fBcb\fR is
439 ignored.
441 If the \fBcb\fR parameters is set to \s-1NULL\s0 and the \fBu\fR parameter is not
442 \&\s-1NULL\s0 then the \fBu\fR parameter is interpreted as a null terminated string
443 to use as the passphrase. If both \fBcb\fR and \fBu\fR are \s-1NULL\s0 then the
444 default callback routine is used which will typically prompt for the
445 passphrase on the current terminal with echoing turned off.
447 The default passphrase callback is sometimes inappropriate (for example
448 in a \s-1GUI\s0 application) so an alternative can be supplied. The callback
449 routine has the following form:
451 .Vb 1
452 \& int cb(char *buf, int size, int rwflag, void *u);
455 \&\fBbuf\fR is the buffer to write the passphrase to. \fBsize\fR is the maximum
456 length of the passphrase (i.e. the size of buf). \fBrwflag\fR is a flag
457 which is set to 0 when reading and 1 when writing. A typical routine
458 will ask the user to verify the passphrase (for example by prompting
459 for it twice) if \fBrwflag\fR is 1. The \fBu\fR parameter has the same
460 value as the \fBu\fR parameter passed to the \s-1PEM\s0 routine. It allows
461 arbitrary data to be passed to the callback by the application
462 (for example a window handle in a \s-1GUI\s0 application). The callback
463 \&\fBmust\fR return the number of characters in the passphrase or 0 if
464 an error occurred.
465 .SH "EXAMPLES"
466 .IX Header "EXAMPLES"
467 Although the \s-1PEM\s0 routines take several arguments in almost all applications
468 most of them are set to 0 or \s-1NULL\s0.
470 Read a certificate in \s-1PEM\s0 format from a \s-1BIO:\s0
472 .Vb 6
473 \& X509 *x;
474 \& x = PEM_read_bio_X509(bp, NULL, 0, NULL);
475 \& if (x == NULL)
476 \&        {
477 \&        /* Error */
478 \&        }
481 Alternative method:
483 .Vb 5
484 \& X509 *x = NULL;
485 \& if (!PEM_read_bio_X509(bp, &x, 0, NULL))
486 \&        {
487 \&        /* Error */
488 \&        }
491 Write a certificate to a \s-1BIO:\s0
493 .Vb 4
494 \& if (!PEM_write_bio_X509(bp, x))
495 \&        {
496 \&        /* Error */
497 \&        }
500 Write an unencrypted private key to a \s-1FILE\s0 pointer:
502 .Vb 4
503 \& if (!PEM_write_PrivateKey(fp, key, NULL, NULL, 0, 0, NULL))
504 \&        {
505 \&        /* Error */
506 \&        }
509 Write a private key (using traditional format) to a \s-1BIO\s0 using
510 triple \s-1DES\s0 encryption, the pass phrase is prompted for:
512 .Vb 4
513 \& if (!PEM_write_bio_PrivateKey(bp, key, EVP_des_ede3_cbc(), NULL, 0, 0, NULL))
514 \&        {
515 \&        /* Error */
516 \&        }
519 Write a private key (using PKCS#8 format) to a \s-1BIO\s0 using triple
520 \&\s-1DES\s0 encryption, using the pass phrase \*(L"hello\*(R":
522 .Vb 4
523 \& if (!PEM_write_bio_PKCS8PrivateKey(bp, key, EVP_des_ede3_cbc(), NULL, 0, 0, "hello"))
524 \&        {
525 \&        /* Error */
526 \&        }
529 Read a private key from a \s-1BIO\s0 using the pass phrase \*(L"hello\*(R":
531 .Vb 5
532 \& key = PEM_read_bio_PrivateKey(bp, NULL, 0, "hello");
533 \& if (key == NULL)
534 \&        {
535 \&        /* Error */
536 \&        }
539 Read a private key from a \s-1BIO\s0 using a pass phrase callback:
541 .Vb 5
542 \& key = PEM_read_bio_PrivateKey(bp, NULL, pass_cb, "My Private Key");
543 \& if (key == NULL)
544 \&        {
545 \&        /* Error */
546 \&        }
549 Skeleton pass phrase callback:
551 .Vb 6
552 \& int pass_cb(char *buf, int size, int rwflag, void *u);
553 \&        {
554 \&        int len;
555 \&        char *tmp;
556 \&        /* We\*(Aqd probably do something else if \*(Aqrwflag\*(Aq is 1 */
557 \&        printf("Enter pass phrase for \e"%s\e"\en", u);
559 \&        /* get pass phrase, length \*(Aqlen\*(Aq into \*(Aqtmp\*(Aq */
560 \&        tmp = "hello";
561 \&        len = strlen(tmp);
563 \&        if (len <= 0) return 0;
564 \&        /* if too long, truncate */
565 \&        if (len > size) len = size;
566 \&        memcpy(buf, tmp, len);
567 \&        return len;
568 \&        }
570 .SH "NOTES"
571 .IX Header "NOTES"
572 The old \fBPrivateKey\fR write routines are retained for compatibility.
573 New applications should write private keys using the
574 \&\fIPEM_write_bio_PKCS8PrivateKey()\fR or \fIPEM_write_PKCS8PrivateKey()\fR routines
575 because they are more secure (they use an iteration count of 2048 whereas
576 the traditional routines use a count of 1) unless compatibility with older
577 versions of OpenSSL is important.
579 The \fBPrivateKey\fR read routines can be used in all applications because
580 they handle all formats transparently.
582 A frequent cause of problems is attempting to use the \s-1PEM\s0 routines like
583 this:
585 .Vb 2
586 \& X509 *x;
587 \& PEM_read_bio_X509(bp, &x, 0, NULL);
590 this is a bug because an attempt will be made to reuse the data at \fBx\fR
591 which is an uninitialised pointer.
592 .SH "PEM ENCRYPTION FORMAT"
593 .IX Header "PEM ENCRYPTION FORMAT"
594 This old \fBPrivateKey\fR routines use a non standard technique for encryption.
596 The private key (or other data) takes the following form:
598 .Vb 3
599 \& \-\-\-\-\-BEGIN RSA PRIVATE KEY\-\-\-\-\-
600 \& Proc\-Type: 4,ENCRYPTED
601 \& DEK\-Info: DES\-EDE3\-CBC,3F17F5316E2BAC89
603 \& ...base64 encoded data...
604 \& \-\-\-\-\-END RSA PRIVATE KEY\-\-\-\-\-
607 The line beginning DEK-Info contains two comma separated pieces of information:
608 the encryption algorithm name as used by \fIEVP_get_cipherbyname()\fR and an 8
609 byte \fBsalt\fR encoded as a set of hexadecimal digits.
611 After this is the base64 encoded encrypted data.
613 The encryption key is determined using \fIEVP_bytestokey()\fR, using \fBsalt\fR and an
614 iteration count of 1. The \s-1IV\s0 used is the value of \fBsalt\fR and *not* the \s-1IV\s0
615 returned by \fIEVP_bytestokey()\fR.
616 .SH "BUGS"
617 .IX Header "BUGS"
618 The \s-1PEM\s0 read routines in some versions of OpenSSL will not correctly reuse
619 an existing structure. Therefore the following:
621 .Vb 1
622 \& PEM_read_bio_X509(bp, &x, 0, NULL);
625 where \fBx\fR already contains a valid certificate, may not work, whereas:
627 .Vb 2
628 \& X509_free(x);
629 \& x = PEM_read_bio_X509(bp, NULL, 0, NULL);
632 is guaranteed to work.
633 .SH "RETURN CODES"
634 .IX Header "RETURN CODES"
635 The read routines return either a pointer to the structure read or \s-1NULL\s0
636 if an error occurred.
638 The write routines return 1 for success or 0 for failure.