]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/PEM_read_bio_PrivateKey.pod
Various typo
[thirdparty/openssl.git] / doc / man3 / PEM_read_bio_PrivateKey.pod
CommitLineData
a29d78e9
DSH
1=pod
2
3=head1 NAME
4
91da5e77 5pem_password_cb,
c952780c 6PEM_read_bio_PrivateKey, PEM_read_PrivateKey, PEM_write_bio_PrivateKey,
05dba815
DSH
7PEM_write_bio_PrivateKey_traditional, PEM_write_PrivateKey,
8PEM_write_bio_PKCS8PrivateKey, PEM_write_PKCS8PrivateKey,
f097f81c
DSH
9PEM_write_bio_PKCS8PrivateKey_nid, PEM_write_PKCS8PrivateKey_nid,
10PEM_read_bio_PUBKEY, PEM_read_PUBKEY, PEM_write_bio_PUBKEY, PEM_write_PUBKEY,
11PEM_read_bio_RSAPrivateKey, PEM_read_RSAPrivateKey,
12PEM_write_bio_RSAPrivateKey, PEM_write_RSAPrivateKey,
13PEM_read_bio_RSAPublicKey, PEM_read_RSAPublicKey, PEM_write_bio_RSAPublicKey,
14PEM_write_RSAPublicKey, PEM_read_bio_RSA_PUBKEY, PEM_read_RSA_PUBKEY,
15PEM_write_bio_RSA_PUBKEY, PEM_write_RSA_PUBKEY, PEM_read_bio_DSAPrivateKey,
16PEM_read_DSAPrivateKey, PEM_write_bio_DSAPrivateKey, PEM_write_DSAPrivateKey,
17PEM_read_bio_DSA_PUBKEY, PEM_read_DSA_PUBKEY, PEM_write_bio_DSA_PUBKEY,
18PEM_write_DSA_PUBKEY, PEM_read_bio_DSAparams, PEM_read_DSAparams,
19PEM_write_bio_DSAparams, PEM_write_DSAparams, PEM_read_bio_DHparams,
20PEM_read_DHparams, PEM_write_bio_DHparams, PEM_write_DHparams,
21PEM_read_bio_X509, PEM_read_X509, PEM_write_bio_X509, PEM_write_X509,
22PEM_read_bio_X509_AUX, PEM_read_X509_AUX, PEM_write_bio_X509_AUX,
23PEM_write_X509_AUX, PEM_read_bio_X509_REQ, PEM_read_X509_REQ,
24PEM_write_bio_X509_REQ, PEM_write_X509_REQ, PEM_write_bio_X509_REQ_NEW,
25PEM_write_X509_REQ_NEW, PEM_read_bio_X509_CRL, PEM_read_X509_CRL,
26PEM_write_bio_X509_CRL, PEM_write_X509_CRL, PEM_read_bio_PKCS7, PEM_read_PKCS7,
a0474357 27PEM_write_bio_PKCS7, PEM_write_PKCS7 - PEM routines
a29d78e9
DSH
28
29=head1 SYNOPSIS
30
31 #include <openssl/pem.h>
32
5bf6d418 33 typedef int pem_password_cb(char *buf, int size, int rwflag, void *u);
91da5e77 34
a29d78e9 35 EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x,
a0474357 36 pem_password_cb *cb, void *u);
a29d78e9 37 EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x,
a0474357 38 pem_password_cb *cb, void *u);
a29d78e9 39 int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
a0474357
RS
40 unsigned char *kstr, int klen,
41 pem_password_cb *cb, void *u);
05dba815
DSH
42 int PEM_write_bio_PrivateKey_traditional(BIO *bp, EVP_PKEY *x,
43 const EVP_CIPHER *enc,
44 unsigned char *kstr, int klen,
45 pem_password_cb *cb, void *u);
a29d78e9 46 int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
a0474357
RS
47 unsigned char *kstr, int klen,
48 pem_password_cb *cb, void *u);
a29d78e9
DSH
49
50 int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
a0474357
RS
51 char *kstr, int klen,
52 pem_password_cb *cb, void *u);
a29d78e9 53 int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
a0474357
RS
54 char *kstr, int klen,
55 pem_password_cb *cb, void *u);
a29d78e9 56 int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
a0474357
RS
57 char *kstr, int klen,
58 pem_password_cb *cb, void *u);
a29d78e9 59 int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
a0474357
RS
60 char *kstr, int klen,
61 pem_password_cb *cb, void *u);
a29d78e9
DSH
62
63 EVP_PKEY *PEM_read_bio_PUBKEY(BIO *bp, EVP_PKEY **x,
a0474357 64 pem_password_cb *cb, void *u);
a29d78e9 65 EVP_PKEY *PEM_read_PUBKEY(FILE *fp, EVP_PKEY **x,
a0474357 66 pem_password_cb *cb, void *u);
a29d78e9
DSH
67 int PEM_write_bio_PUBKEY(BIO *bp, EVP_PKEY *x);
68 int PEM_write_PUBKEY(FILE *fp, EVP_PKEY *x);
69
70 RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **x,
a0474357 71 pem_password_cb *cb, void *u);
a29d78e9 72 RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **x,
a0474357 73 pem_password_cb *cb, void *u);
a29d78e9 74 int PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc,
a0474357
RS
75 unsigned char *kstr, int klen,
76 pem_password_cb *cb, void *u);
a29d78e9 77 int PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc,
a0474357
RS
78 unsigned char *kstr, int klen,
79 pem_password_cb *cb, void *u);
a29d78e9
DSH
80
81 RSA *PEM_read_bio_RSAPublicKey(BIO *bp, RSA **x,
a0474357 82 pem_password_cb *cb, void *u);
a29d78e9 83 RSA *PEM_read_RSAPublicKey(FILE *fp, RSA **x,
a0474357 84 pem_password_cb *cb, void *u);
a29d78e9 85 int PEM_write_bio_RSAPublicKey(BIO *bp, RSA *x);
a29d78e9
DSH
86 int PEM_write_RSAPublicKey(FILE *fp, RSA *x);
87
88 RSA *PEM_read_bio_RSA_PUBKEY(BIO *bp, RSA **x,
a0474357 89 pem_password_cb *cb, void *u);
a29d78e9 90 RSA *PEM_read_RSA_PUBKEY(FILE *fp, RSA **x,
a0474357 91 pem_password_cb *cb, void *u);
a29d78e9 92 int PEM_write_bio_RSA_PUBKEY(BIO *bp, RSA *x);
a29d78e9
DSH
93 int PEM_write_RSA_PUBKEY(FILE *fp, RSA *x);
94
95 DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **x,
a0474357 96 pem_password_cb *cb, void *u);
a29d78e9 97 DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **x,
a0474357 98 pem_password_cb *cb, void *u);
a29d78e9 99 int PEM_write_bio_DSAPrivateKey(BIO *bp, DSA *x, const EVP_CIPHER *enc,
a0474357
RS
100 unsigned char *kstr, int klen,
101 pem_password_cb *cb, void *u);
a29d78e9 102 int PEM_write_DSAPrivateKey(FILE *fp, DSA *x, const EVP_CIPHER *enc,
a0474357
RS
103 unsigned char *kstr, int klen,
104 pem_password_cb *cb, void *u);
a29d78e9
DSH
105
106 DSA *PEM_read_bio_DSA_PUBKEY(BIO *bp, DSA **x,
a0474357 107 pem_password_cb *cb, void *u);
a29d78e9 108 DSA *PEM_read_DSA_PUBKEY(FILE *fp, DSA **x,
a0474357 109 pem_password_cb *cb, void *u);
a29d78e9 110 int PEM_write_bio_DSA_PUBKEY(BIO *bp, DSA *x);
a29d78e9
DSH
111 int PEM_write_DSA_PUBKEY(FILE *fp, DSA *x);
112
113 DSA *PEM_read_bio_DSAparams(BIO *bp, DSA **x, pem_password_cb *cb, void *u);
a29d78e9 114 DSA *PEM_read_DSAparams(FILE *fp, DSA **x, pem_password_cb *cb, void *u);
a29d78e9 115 int PEM_write_bio_DSAparams(BIO *bp, DSA *x);
a29d78e9
DSH
116 int PEM_write_DSAparams(FILE *fp, DSA *x);
117
118 DH *PEM_read_bio_DHparams(BIO *bp, DH **x, pem_password_cb *cb, void *u);
a29d78e9 119 DH *PEM_read_DHparams(FILE *fp, DH **x, pem_password_cb *cb, void *u);
a29d78e9 120 int PEM_write_bio_DHparams(BIO *bp, DH *x);
a29d78e9
DSH
121 int PEM_write_DHparams(FILE *fp, DH *x);
122
123 X509 *PEM_read_bio_X509(BIO *bp, X509 **x, pem_password_cb *cb, void *u);
a29d78e9 124 X509 *PEM_read_X509(FILE *fp, X509 **x, pem_password_cb *cb, void *u);
a29d78e9 125 int PEM_write_bio_X509(BIO *bp, X509 *x);
a29d78e9
DSH
126 int PEM_write_X509(FILE *fp, X509 *x);
127
128 X509 *PEM_read_bio_X509_AUX(BIO *bp, X509 **x, pem_password_cb *cb, void *u);
a29d78e9 129 X509 *PEM_read_X509_AUX(FILE *fp, X509 **x, pem_password_cb *cb, void *u);
a29d78e9 130 int PEM_write_bio_X509_AUX(BIO *bp, X509 *x);
a29d78e9
DSH
131 int PEM_write_X509_AUX(FILE *fp, X509 *x);
132
133 X509_REQ *PEM_read_bio_X509_REQ(BIO *bp, X509_REQ **x,
a0474357 134 pem_password_cb *cb, void *u);
a29d78e9 135 X509_REQ *PEM_read_X509_REQ(FILE *fp, X509_REQ **x,
a0474357 136 pem_password_cb *cb, void *u);
a29d78e9 137 int PEM_write_bio_X509_REQ(BIO *bp, X509_REQ *x);
a29d78e9 138 int PEM_write_X509_REQ(FILE *fp, X509_REQ *x);
a29d78e9 139 int PEM_write_bio_X509_REQ_NEW(BIO *bp, X509_REQ *x);
a29d78e9
DSH
140 int PEM_write_X509_REQ_NEW(FILE *fp, X509_REQ *x);
141
142 X509_CRL *PEM_read_bio_X509_CRL(BIO *bp, X509_CRL **x,
a0474357 143 pem_password_cb *cb, void *u);
a29d78e9 144 X509_CRL *PEM_read_X509_CRL(FILE *fp, X509_CRL **x,
a0474357 145 pem_password_cb *cb, void *u);
a29d78e9
DSH
146 int PEM_write_bio_X509_CRL(BIO *bp, X509_CRL *x);
147 int PEM_write_X509_CRL(FILE *fp, X509_CRL *x);
148
149 PKCS7 *PEM_read_bio_PKCS7(BIO *bp, PKCS7 **x, pem_password_cb *cb, void *u);
a29d78e9 150 PKCS7 *PEM_read_PKCS7(FILE *fp, PKCS7 **x, pem_password_cb *cb, void *u);
a29d78e9 151 int PEM_write_bio_PKCS7(BIO *bp, PKCS7 *x);
a29d78e9
DSH
152 int PEM_write_PKCS7(FILE *fp, PKCS7 *x);
153
a29d78e9
DSH
154=head1 DESCRIPTION
155
156The PEM functions read or write structures in PEM format. In
157this sense PEM format is simply base64 encoded data surrounded
158by header lines.
159
160For more details about the meaning of arguments see the
161B<PEM FUNCTION ARGUMENTS> section.
162
163Each operation has four functions associated with it. For
164clarity the term "B<foobar> functions" will be used to collectively
165refer to the PEM_read_bio_foobar(), PEM_read_foobar(),
166PEM_write_bio_foobar() and PEM_write_foobar() functions.
167
05dba815
DSH
168The B<PrivateKey> functions read or write a private key in PEM format using an
169EVP_PKEY structure. The write routines use PKCS#8 private key format and are
170equivalent to PEM_write_bio_PKCS8PrivateKey().The read functions transparently
171handle traditional and PKCS#8 format encrypted and unencrypted keys.
a29d78e9 172
a95d7574
RS
173PEM_write_bio_PrivateKey_traditional() writes out a private key in the
174"traditional" format with a simple private key marker and should only
175be used for compatibility with legacy programs.
05dba815
DSH
176
177PEM_write_bio_PKCS8PrivateKey() and PEM_write_PKCS8PrivateKey() write a private
178key in an EVP_PKEY structure in PKCS#8 EncryptedPrivateKeyInfo format using
179PKCS#5 v2.0 password based encryption algorithms. The B<cipher> argument
180specifies the encryption algorithm to use: unlike some other PEM routines the
181encryption is applied at the PKCS#8 level and not in the PEM headers. If
182B<cipher> is NULL then no encryption is used and a PKCS#8 PrivateKeyInfo
183structure is used instead.
a29d78e9
DSH
184
185PEM_write_bio_PKCS8PrivateKey_nid() and PEM_write_PKCS8PrivateKey_nid()
186also write out a private key as a PKCS#8 EncryptedPrivateKeyInfo however
187it uses PKCS#5 v1.5 or PKCS#12 encryption algorithms instead. The algorithm
188to use is specified in the B<nid> parameter and should be the NID of the
189corresponding OBJECT IDENTIFIER (see NOTES section).
190
191The B<PUBKEY> functions process a public key using an EVP_PKEY
192structure. The public key is encoded as a SubjectPublicKeyInfo
193structure.
194
195The B<RSAPrivateKey> functions process an RSA private key using an
05dba815
DSH
196RSA structure. The write routines uses traditional format. The read
197routines handles the same formats as the B<PrivateKey>
a29d78e9
DSH
198functions but an error occurs if the private key is not RSA.
199
200The B<RSAPublicKey> functions process an RSA public key using an
201RSA structure. The public key is encoded using a PKCS#1 RSAPublicKey
202structure.
203
204The B<RSA_PUBKEY> functions also process an RSA public key using
205an RSA structure. However the public key is encoded using a
206SubjectPublicKeyInfo structure and an error occurs if the public
207key is not RSA.
208
209The B<DSAPrivateKey> functions process a DSA private key using a
05dba815
DSH
210DSA structure. The write routines uses traditional format. The read
211routines handles the same formats as the B<PrivateKey>
a29d78e9
DSH
212functions but an error occurs if the private key is not DSA.
213
214The B<DSA_PUBKEY> functions process a DSA public key using
215a DSA structure. The public key is encoded using a
216SubjectPublicKeyInfo structure and an error occurs if the public
217key is not DSA.
218
219The B<DSAparams> functions process DSA parameters using a DSA
f097f81c
DSH
220structure. The parameters are encoded using a Dss-Parms structure
221as defined in RFC2459.
a29d78e9
DSH
222
223The B<DHparams> functions process DH parameters using a DH
224structure. The parameters are encoded using a PKCS#3 DHparameter
225structure.
226
227The B<X509> functions process an X509 certificate using an X509
228structure. They will also process a trusted X509 certificate but
229any trust settings are discarded.
230
231The B<X509_AUX> functions process a trusted X509 certificate using
1bc74519 232an X509 structure.
a29d78e9
DSH
233
234The B<X509_REQ> and B<X509_REQ_NEW> functions process a PKCS#10
235certificate request using an X509_REQ structure. The B<X509_REQ>
236write functions use B<CERTIFICATE REQUEST> in the header whereas
237the B<X509_REQ_NEW> functions use B<NEW CERTIFICATE REQUEST>
238(as required by some CAs). The B<X509_REQ> read functions will
239handle either form so there are no B<X509_REQ_NEW> read functions.
240
241The B<X509_CRL> functions process an X509 CRL using an X509_CRL
242structure.
243
244The B<PKCS7> functions process a PKCS#7 ContentInfo using a PKCS7
245structure.
246
a29d78e9
DSH
247=head1 PEM FUNCTION ARGUMENTS
248
249The PEM functions have many common arguments.
250
251The B<bp> BIO parameter (if present) specifies the BIO to read from
252or write to.
253
254The B<fp> FILE parameter (if present) specifies the FILE pointer to
255read from or write to.
256
257The PEM read functions all take an argument B<TYPE **x> and return
258a B<TYPE *> pointer. Where B<TYPE> is whatever structure the function
259uses. If B<x> is NULL then the parameter is ignored. If B<x> is not
260NULL but B<*x> is NULL then the structure returned will be written
261to B<*x>. If neither B<x> nor B<*x> is NULL then an attempt is made
262to reuse the structure at B<*x> (but see BUGS and EXAMPLES sections).
263Irrespective of the value of B<x> a pointer to the structure is always
264returned (or NULL if an error occurred).
265
266The PEM functions which write private keys take an B<enc> parameter
267which specifies the encryption algorithm to use, encryption is done
268at the PEM level. If this parameter is set to NULL then the private
269key is written in unencrypted form.
270
271The B<cb> argument is the callback to use when querying for the pass
272phrase used for encrypted PEM structures (normally only private keys).
273
274For the PEM write routines if the B<kstr> parameter is not NULL then
275B<klen> bytes at B<kstr> are used as the passphrase and B<cb> is
276ignored.
277
278If the B<cb> parameters is set to NULL and the B<u> parameter is not
279NULL then the B<u> parameter is interpreted as a null terminated string
280to use as the passphrase. If both B<cb> and B<u> are NULL then the
281default callback routine is used which will typically prompt for the
282passphrase on the current terminal with echoing turned off.
283
284The default passphrase callback is sometimes inappropriate (for example
285in a GUI application) so an alternative can be supplied. The callback
286routine has the following form:
287
288 int cb(char *buf, int size, int rwflag, void *u);
289
290B<buf> is the buffer to write the passphrase to. B<size> is the maximum
291length of the passphrase (i.e. the size of buf). B<rwflag> is a flag
292which is set to 0 when reading and 1 when writing. A typical routine
293will ask the user to verify the passphrase (for example by prompting
294for it twice) if B<rwflag> is 1. The B<u> parameter has the same
295value as the B<u> parameter passed to the PEM routine. It allows
296arbitrary data to be passed to the callback by the application
297(for example a window handle in a GUI application). The callback
298B<must> return the number of characters in the passphrase or 0 if
299an error occurred.
300
301=head1 EXAMPLES
302
303Although the PEM routines take several arguments in almost all applications
304most of them are set to 0 or NULL.
305
306Read a certificate in PEM format from a BIO:
307
308 X509 *x;
e9b77246 309
e88c5777 310 x = PEM_read_bio_X509(bp, NULL, 0, NULL);
2947af32 311 if (x == NULL)
a0474357 312 /* Error */
a29d78e9
DSH
313
314Alternative method:
315
316 X509 *x = NULL;
e9b77246 317
2947af32 318 if (!PEM_read_bio_X509(bp, &x, 0, NULL))
a0474357 319 /* Error */
a29d78e9
DSH
320
321Write a certificate to a BIO:
322
2947af32 323 if (!PEM_write_bio_X509(bp, x))
a0474357 324 /* Error */
a29d78e9
DSH
325
326Write a private key (using traditional format) to a BIO using
327triple DES encryption, the pass phrase is prompted for:
328
2947af32 329 if (!PEM_write_bio_PrivateKey(bp, key, EVP_des_ede3_cbc(), NULL, 0, 0, NULL))
a0474357 330 /* Error */
a29d78e9
DSH
331
332Write a private key (using PKCS#8 format) to a BIO using triple
333DES encryption, using the pass phrase "hello":
334
2947af32
BB
335 if (!PEM_write_bio_PKCS8PrivateKey(bp, key, EVP_des_ede3_cbc(),
336 NULL, 0, 0, "hello"))
a0474357 337 /* Error */
a29d78e9
DSH
338
339Read a private key from a BIO using a pass phrase callback:
340
341 key = PEM_read_bio_PrivateKey(bp, NULL, pass_cb, "My Private Key");
2947af32 342 if (key == NULL)
a0474357 343 /* Error */
a29d78e9
DSH
344
345Skeleton pass phrase callback:
346
a0474357
RS
347 int pass_cb(char *buf, int size, int rwflag, void *u)
348 {
349 int len;
350 char *tmp;
351
352 /* We'd probably do something else if 'rwflag' is 1 */
1bc74519 353 printf("Enter pass phrase for \"%s\"\n", (char *)u);
a29d78e9 354
a0474357
RS
355 /* get pass phrase, length 'len' into 'tmp' */
356 tmp = "hello";
357 len = strlen(tmp);
358 if (len <= 0)
359 return 0;
a29d78e9 360
a0474357
RS
361 if (len > size)
362 len = size;
363 memcpy(buf, tmp, len);
364 return len;
365 }
06623ff0 366
a29d78e9
DSH
367=head1 NOTES
368
369The old B<PrivateKey> write routines are retained for compatibility.
370New applications should write private keys using the
371PEM_write_bio_PKCS8PrivateKey() or PEM_write_PKCS8PrivateKey() routines
372because they are more secure (they use an iteration count of 2048 whereas
373the traditional routines use a count of 1) unless compatibility with older
374versions of OpenSSL is important.
375
376The B<PrivateKey> read routines can be used in all applications because
377they handle all formats transparently.
378
379A frequent cause of problems is attempting to use the PEM routines like
380this:
381
382 X509 *x;
e9b77246 383
a29d78e9
DSH
384 PEM_read_bio_X509(bp, &x, 0, NULL);
385
386this is a bug because an attempt will be made to reuse the data at B<x>
387which is an uninitialised pointer.
388
06623ff0
DSH
389=head1 PEM ENCRYPTION FORMAT
390
a0474357 391These old B<PrivateKey> routines use a non standard technique for encryption.
06623ff0 392
1bc74519 393The private key (or other data) takes the following form:
06623ff0
DSH
394
395 -----BEGIN RSA PRIVATE KEY-----
396 Proc-Type: 4,ENCRYPTED
397 DEK-Info: DES-EDE3-CBC,3F17F5316E2BAC89
398
399 ...base64 encoded data...
400 -----END RSA PRIVATE KEY-----
401
a0474357
RS
402The line beginning with I<Proc-Type> contains the version and the
403protection on the encapsulated data. The line beginning I<DEK-Info>
404contains two comma separated values: the encryption algorithm name as
405used by EVP_get_cipherbyname() and an initialization vector used by the
406cipher encoded as a set of hexadecimal digits. After those two lines is
407the base64-encoded encrypted data.
06623ff0 408
a0474357
RS
409The encryption key is derived using EVP_BytesToKey(). The cipher's
410initialization vector is passed to EVP_BytesToKey() as the B<salt>
411parameter. Internally, B<PKCS5_SALT_LEN> bytes of the salt are used
412(regardless of the size of the initialization vector). The user's
b9b6a7e5 413password is passed to EVP_BytesToKey() using the B<data> and B<datal>
a0474357
RS
414parameters. Finally, the library uses an iteration count of 1 for
415EVP_BytesToKey().
06623ff0 416
05dba815 417The B<key> derived by EVP_BytesToKey() along with the original initialization
a0474357
RS
418vector is then used to decrypt the encrypted data. The B<iv> produced by
419EVP_BytesToKey() is not utilized or needed, and NULL should be passed to
420the function.
421
422The pseudo code to derive the key would look similar to:
423
424 EVP_CIPHER* cipher = EVP_des_ede3_cbc();
425 EVP_MD* md = EVP_md5();
426
427 unsigned int nkey = EVP_CIPHER_key_length(cipher);
428 unsigned int niv = EVP_CIPHER_iv_length(cipher);
429 unsigned char key[nkey];
430 unsigned char iv[niv];
431
432 memcpy(iv, HexToBin("3F17F5316E2BAC89"), niv);
433 rc = EVP_BytesToKey(cipher, md, iv /*salt*/, pword, plen, 1, key, NULL /*iv*/);
2947af32 434 if (rc != nkey)
a0474357 435 /* Error */
a0474357
RS
436
437 /* On success, use key and iv to initialize the cipher */
06623ff0 438
a29d78e9
DSH
439=head1 BUGS
440
441The PEM read routines in some versions of OpenSSL will not correctly reuse
442an existing structure. Therefore the following:
443
e88c5777 444 PEM_read_bio_X509(bp, &x, 0, NULL);
a29d78e9 445
1bc74519 446where B<x> already contains a valid certificate, may not work, whereas:
a29d78e9
DSH
447
448 X509_free(x);
e88c5777 449 x = PEM_read_bio_X509(bp, NULL, 0, NULL);
a29d78e9
DSH
450
451is guaranteed to work.
452
453=head1 RETURN CODES
454
455The read routines return either a pointer to the structure read or NULL
9449e385 456if an error occurred.
a29d78e9
DSH
457
458The write routines return 1 for success or 0 for failure.
d48e78f0 459
a0474357
RS
460=head1 HISTORY
461
462The old Netscape certificate sequences were no longer documented
a95d7574 463in OpenSSL 1.1.0; applications should use the PKCS7 standard instead
a0474357
RS
464as they will be formally deprecated in a future releases.
465
d48e78f0
JW
466=head1 SEE ALSO
467
a0474357 468L<EVP_EncryptInit(3)>, L<EVP_BytesToKey(3)>
99ec4fdb 469
e2f92610
RS
470=head1 COPYRIGHT
471
472Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
473
474Licensed under the OpenSSL license (the "License"). You may not use
475this file except in compliance with the License. You can obtain a copy
476in the file LICENSE in the source distribution or at
477L<https://www.openssl.org/source/license.html>.
478
479=cut