d2i_PrivateKey.pod 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. =pod
  2. =head1 NAME
  3. d2i_PrivateKey, d2i_PublicKey, d2i_AutoPrivateKey,
  4. i2d_PrivateKey, i2d_PublicKey,
  5. d2i_PrivateKey_bio, d2i_PrivateKey_fp
  6. - decode and encode functions for reading and saving EVP_PKEY structures
  7. =head1 SYNOPSIS
  8. #include <openssl/evp.h>
  9. EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp,
  10. long length);
  11. EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
  12. long length);
  13. EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp,
  14. long length);
  15. int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp);
  16. int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);
  17. EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a);
  18. EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a)
  19. =head1 DESCRIPTION
  20. d2i_PrivateKey() decodes a private key using algorithm B<type>. It attempts to
  21. use any key specific format or PKCS#8 unencrypted PrivateKeyInfo format. The
  22. B<type> parameter should be a public key algorithm constant such as
  23. B<EVP_PKEY_RSA>. An error occurs if the decoded key does not match B<type>.
  24. d2i_PublicKey() does the same for public keys.
  25. d2i_AutoPrivateKey() is similar to d2i_PrivateKey() except it attempts to
  26. automatically detect the private key format.
  27. i2d_PrivateKey() encodes B<key>. It uses a key specific format or, if none is
  28. defined for that key type, PKCS#8 unencrypted PrivateKeyInfo format.
  29. i2d_PublicKey() does the same for public keys.
  30. These functions are similar to the d2i_X509() functions; see L<d2i_X509(3)>.
  31. =head1 NOTES
  32. All these functions use DER format and unencrypted keys. Applications wishing
  33. to encrypt or decrypt private keys should use other functions such as
  34. d2i_PKCS8PrivateKey() instead.
  35. If the B<*a> is not NULL when calling d2i_PrivateKey() or d2i_AutoPrivateKey()
  36. (i.e. an existing structure is being reused) and the key format is PKCS#8
  37. then B<*a> will be freed and replaced on a successful call.
  38. =head1 RETURN VALUES
  39. d2i_PrivateKey() and d2i_AutoPrivateKey() return a valid B<EVP_KEY> structure
  40. or B<NULL> if an error occurs. The error code can be obtained by calling
  41. L<ERR_get_error(3)>.
  42. i2d_PrivateKey() returns the number of bytes successfully encoded or a
  43. negative value if an error occurs. The error code can be obtained by calling
  44. L<ERR_get_error(3)>.
  45. =head1 SEE ALSO
  46. L<crypto(7)>,
  47. L<d2i_PKCS8PrivateKey_bio(3)>
  48. =head1 COPYRIGHT
  49. Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
  50. Licensed under the Apache License 2.0 (the "License"). You may not use
  51. this file except in compliance with the License. You can obtain a copy
  52. in the file LICENSE in the source distribution or at
  53. L<https://www.openssl.org/source/license.html>.
  54. =cut