d2i_PrivateKey.3ossl 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "D2I_PRIVATEKEY 3ossl"
  58. .TH D2I_PRIVATEKEY 3ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. d2i_PrivateKey_ex, d2i_PrivateKey, d2i_PublicKey, d2i_KeyParams,
  65. d2i_AutoPrivateKey_ex, d2i_AutoPrivateKey, i2d_PrivateKey, i2d_PublicKey,
  66. i2d_KeyParams, i2d_KeyParams_bio, d2i_PrivateKey_ex_bio, d2i_PrivateKey_bio,
  67. d2i_PrivateKey_ex_fp, d2i_PrivateKey_fp, d2i_KeyParams_bio, i2d_PrivateKey_bio,
  68. i2d_PrivateKey_fp
  69. \&\- decode and encode functions for reading and saving EVP_PKEY structures
  70. .SH SYNOPSIS
  71. .IX Header "SYNOPSIS"
  72. .Vb 1
  73. \& #include <openssl/evp.h>
  74. \&
  75. \& EVP_PKEY *d2i_PrivateKey_ex(int type, EVP_PKEY **a, const unsigned char **pp,
  76. \& long length, OSSL_LIB_CTX *libctx,
  77. \& const char *propq);
  78. \& EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp,
  79. \& long length);
  80. \& EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
  81. \& long length);
  82. \& EVP_PKEY *d2i_KeyParams(int type, EVP_PKEY **a, const unsigned char **pp,
  83. \& long length);
  84. \& EVP_PKEY *d2i_AutoPrivateKey_ex(EVP_PKEY **a, const unsigned char **pp,
  85. \& long length, OSSL_LIB_CTX *libctx,
  86. \& const char *propq);
  87. \& EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp,
  88. \& long length);
  89. \&
  90. \& int i2d_PrivateKey(const EVP_PKEY *a, unsigned char **pp);
  91. \& int i2d_PublicKey(const EVP_PKEY *a, unsigned char **pp);
  92. \& int i2d_KeyParams(const EVP_PKEY *a, unsigned char **pp);
  93. \& int i2d_KeyParams_bio(BIO *bp, const EVP_PKEY *pkey);
  94. \& EVP_PKEY *d2i_KeyParams_bio(int type, EVP_PKEY **a, BIO *in);
  95. \&
  96. \&
  97. \& #include <openssl/x509.h>
  98. \&
  99. \& EVP_PKEY *d2i_PrivateKey_ex_bio(BIO *bp, EVP_PKEY **a, OSSL_LIB_CTX *libctx,
  100. \& const char *propq);
  101. \& EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a);
  102. \& EVP_PKEY *d2i_PrivateKey_ex_fp(FILE *fp, EVP_PKEY **a, OSSL_LIB_CTX *libctx,
  103. \& const char *propq);
  104. \& EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a);
  105. \&
  106. \& int i2d_PrivateKey_bio(BIO *bp, const EVP_PKEY *pkey);
  107. \& int i2d_PrivateKey_fp(FILE *fp, const EVP_PKEY *pkey);
  108. .Ve
  109. .SH DESCRIPTION
  110. .IX Header "DESCRIPTION"
  111. \&\fBd2i_PrivateKey_ex()\fR decodes a private key using algorithm \fItype\fR. It attempts
  112. to use any key-specific format or PKCS#8 unencrypted PrivateKeyInfo format.
  113. The \fItype\fR parameter should be a public key algorithm constant such as
  114. \&\fBEVP_PKEY_RSA\fR. An error occurs if the decoded key does not match \fItype\fR. Some
  115. private key decoding implementations may use cryptographic algorithms (for
  116. example to automatically derive the public key if it is not explicitly
  117. included in the encoding). In this case the supplied library context \fIlibctx\fR
  118. and property query string \fIpropq\fR are used.
  119. If successful and the \fIa\fR parameter is not NULL the function assigns the
  120. returned \fBEVP_PKEY\fR structure pointer to \fI*a\fR, overwriting any previous value.
  121. .PP
  122. \&\fBd2i_PrivateKey()\fR does the same as \fBd2i_PrivateKey_ex()\fR except that the default
  123. library context and property query string are used.
  124. \&\fBd2i_PublicKey()\fR does the same for public keys.
  125. \&\fBd2i_KeyParams()\fR does the same for key parameters.
  126. .PP
  127. The \fBd2i_PrivateKey_ex_bio()\fR and \fBd2i_PrivateKey_bio()\fR functions are similar to
  128. \&\fBd2i_PrivateKey_ex()\fR and \fBd2i_PrivateKey()\fR respectively except that they decode
  129. the data read from the given BIO. The \fBd2i_PrivateKey_ex_fp()\fR and
  130. \&\fBd2i_PrivateKey_fp()\fR functions are the same except that they read the data from
  131. the given FILE.
  132. .PP
  133. \&\fBd2i_AutoPrivateKey_ex()\fR and \fBd2i_AutoPrivateKey()\fR are similar to
  134. \&\fBd2i_PrivateKey_ex()\fR and \fBd2i_PrivateKey()\fR respectively except that they attempt
  135. to automatically detect the private key format.
  136. .PP
  137. \&\fBi2d_PrivateKey()\fR encodes \fIa\fR. It uses a key specific format or, if none is
  138. defined for that key type, PKCS#8 unencrypted PrivateKeyInfo format.
  139. \&\fBi2d_PublicKey()\fR does the same for public keys.
  140. \&\fBi2d_KeyParams()\fR does the same for key parameters.
  141. These functions are similar to the \fBd2i_X509()\fR functions; see \fBd2i_X509\fR\|(3).
  142. \&\fBi2d_PrivateKey_bio()\fR and \fBi2d_PrivateKey_fp()\fR do the same thing except that they
  143. encode to a \fBBIO\fR or \fBFILE\fR respectively. Again, these work similarly to the
  144. functions described in \fBd2i_X509\fR\|(3).
  145. .SH NOTES
  146. .IX Header "NOTES"
  147. All the functions that operate on data in memory update the data pointer \fI*pp\fR
  148. after a successful operation, just like the other d2i and i2d functions;
  149. see \fBd2i_X509\fR\|(3).
  150. .PP
  151. All these functions use DER format and unencrypted keys. Applications wishing
  152. to encrypt or decrypt private keys should use other functions such as
  153. \&\fBd2i_PKCS8PrivateKey()\fR instead.
  154. .PP
  155. To decode a key with type \fBEVP_PKEY_EC\fR, \fBd2i_PublicKey()\fR requires \fI*a\fR to be
  156. a non-NULL EVP_PKEY structure assigned an EC_KEY structure referencing the proper
  157. EC_GROUP.
  158. .SH "RETURN VALUES"
  159. .IX Header "RETURN VALUES"
  160. The \fBd2i_PrivateKey_ex()\fR, \fBd2i_PrivateKey()\fR, \fBd2i_AutoPrivateKey_ex()\fR,
  161. \&\fBd2i_AutoPrivateKey()\fR, \fBd2i_PrivateKey_ex_bio()\fR, \fBd2i_PrivateKey_bio()\fR,
  162. \&\fBd2i_PrivateKey_ex_fp()\fR, \fBd2i_PrivateKey_fp()\fR, \fBd2i_PublicKey()\fR, \fBd2i_KeyParams()\fR
  163. and \fBd2i_KeyParams_bio()\fR functions return a valid \fBEVP_PKEY\fR structure or NULL if
  164. an error occurs. The error code can be obtained by calling \fBERR_get_error\fR\|(3).
  165. .PP
  166. \&\fBi2d_PrivateKey()\fR, \fBi2d_PublicKey()\fR and \fBi2d_KeyParams()\fR return the number of
  167. bytes successfully encoded or a negative value if an error occurs. The error
  168. code can be obtained by calling \fBERR_get_error\fR\|(3).
  169. .PP
  170. \&\fBi2d_PrivateKey_bio()\fR, \fBi2d_PrivateKey_fp()\fR and \fBi2d_KeyParams_bio()\fR return 1 if
  171. successfully encoded or zero if an error occurs.
  172. .SH "SEE ALSO"
  173. .IX Header "SEE ALSO"
  174. \&\fBcrypto\fR\|(7),
  175. \&\fBd2i_PKCS8PrivateKey_bio\fR\|(3)
  176. .SH HISTORY
  177. .IX Header "HISTORY"
  178. \&\fBd2i_PrivateKey_ex()\fR, \fBd2i_PrivateKey_ex_bio()\fR, \fBd2i_PrivateKey_ex_fp()\fR, and
  179. \&\fBd2i_AutoPrivateKey_ex()\fR were added in OpenSSL 3.0.
  180. .SH COPYRIGHT
  181. .IX Header "COPYRIGHT"
  182. Copyright 2017\-2021 The OpenSSL Project Authors. All Rights Reserved.
  183. .PP
  184. Licensed under the Apache License 2.0 (the "License"). You may not use
  185. this file except in compliance with the License. You can obtain a copy
  186. in the file LICENSE in the source distribution or at
  187. <https://www.openssl.org/source/license.html>.