summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/doc/PEM_read_bio_PrivateKey.pod
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/doc/PEM_read_bio_PrivateKey.pod56
1 files changed, 27 insertions, 29 deletions
diff --git a/src/lib/libcrypto/doc/PEM_read_bio_PrivateKey.pod b/src/lib/libcrypto/doc/PEM_read_bio_PrivateKey.pod
index 0d9270985a..6d87079a84 100644
--- a/src/lib/libcrypto/doc/PEM_read_bio_PrivateKey.pod
+++ b/src/lib/libcrypto/doc/PEM_read_bio_PrivateKey.pod
@@ -353,71 +353,67 @@ Read a certificate in PEM format from a BIO:
353 353
354 X509 *x; 354 X509 *x;
355 x = PEM_read_bio_X509(bp, NULL, 0, NULL); 355 x = PEM_read_bio_X509(bp, NULL, 0, NULL);
356 if (x == NULL) 356 if (x == NULL) {
357 {
358 /* Error */ 357 /* Error */
359 } 358 }
360 359
361Alternative method: 360Alternative method:
362 361
363 X509 *x = NULL; 362 X509 *x = NULL;
364 if (!PEM_read_bio_X509(bp, &x, 0, NULL)) 363 if (!PEM_read_bio_X509(bp, &x, 0, NULL)) {
365 {
366 /* Error */ 364 /* Error */
367 } 365 }
368 366
369Write a certificate to a BIO: 367Write a certificate to a BIO:
370 368
371 if (!PEM_write_bio_X509(bp, x)) 369 if (!PEM_write_bio_X509(bp, x)) {
372 {
373 /* Error */ 370 /* Error */
374 } 371 }
375 372
376Write an unencrypted private key to a FILE pointer: 373Write an unencrypted private key to a FILE pointer:
377 374
378 if (!PEM_write_PrivateKey(fp, key, NULL, NULL, 0, 0, NULL)) 375 if (!PEM_write_PrivateKey(fp, key, NULL, NULL, 0, 0, NULL)) {
379 {
380 /* Error */ 376 /* Error */
381 } 377 }
382 378
383Write a private key (using traditional format) to a BIO using 379Write a private key (using traditional format) to a BIO using
384triple DES encryption, the pass phrase is prompted for: 380triple DES encryption, the pass phrase is prompted for:
385 381
386 if (!PEM_write_bio_PrivateKey(bp, key, EVP_des_ede3_cbc(), NULL, 0, 0, NULL)) 382 if (!PEM_write_bio_PrivateKey(bp, key, EVP_des_ede3_cbc(),
387 { 383 NULL, 0, 0, NULL)) {
388 /* Error */ 384 /* Error */
389 } 385 }
390 386
391Write a private key (using PKCS#8 format) to a BIO using triple 387Write a private key (using PKCS#8 format) to a BIO using triple
392DES encryption, using the pass phrase "hello": 388DES encryption, using the pass phrase "hello":
393 389
394 if (!PEM_write_bio_PKCS8PrivateKey(bp, key, EVP_des_ede3_cbc(), NULL, 0, 0, "hello")) 390 if (!PEM_write_bio_PKCS8PrivateKey(bp, key, EVP_des_ede3_cbc(),
395 { 391 NULL, 0, 0, "hello")) {
396 /* Error */ 392 /* Error */
397 } 393 }
398 394
399Read a private key from a BIO using the pass phrase "hello": 395Read a private key from a BIO using the pass phrase "hello":
400 396
401 key = PEM_read_bio_PrivateKey(bp, NULL, 0, "hello"); 397 key = PEM_read_bio_PrivateKey(bp, NULL, 0, "hello");
402 if (key == NULL) 398 if (key == NULL) {
403 {
404 /* Error */ 399 /* Error */
405 } 400 }
406 401
407Read a private key from a BIO using a pass phrase callback: 402Read a private key from a BIO using a pass phrase callback:
408 403
409 key = PEM_read_bio_PrivateKey(bp, NULL, pass_cb, "My Private Key"); 404 key = PEM_read_bio_PrivateKey(bp, NULL, pass_cb, "My Private Key");
410 if (key == NULL) 405 if (key == NULL) {
411 {
412 /* Error */ 406 /* Error */
413 } 407 }
414 408
415Skeleton pass phrase callback: 409Skeleton pass phrase callback:
416 410
417 int pass_cb(char *buf, int size, int rwflag, void *u); 411 int
418 { 412 pass_cb(char *buf, int size, int rwflag, void *u)
413 {
419 int len; 414 int len;
420 char *tmp; 415 char *tmp;
416
421 /* We'd probably do something else if 'rwflag' is 1 */ 417 /* We'd probably do something else if 'rwflag' is 1 */
422 printf("Enter pass phrase for \"%s\"\n", u); 418 printf("Enter pass phrase for \"%s\"\n", u);
423 419
@@ -425,12 +421,14 @@ Skeleton pass phrase callback:
425 tmp = "hello"; 421 tmp = "hello";
426 len = strlen(tmp); 422 len = strlen(tmp);
427 423
428 if (len <= 0) return 0; 424 if (len == 0)
425 return 0;
429 /* if too long, truncate */ 426 /* if too long, truncate */
430 if (len > size) len = size; 427 if (len > size)
428 len = size;
431 memcpy(buf, tmp, len); 429 memcpy(buf, tmp, len);
432 return len; 430 return len;
433 } 431 }
434 432
435=head1 NOTES 433=head1 NOTES
436 434