d2i_PrivateKey.pod 3.5 KB

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