Debian Codegraph @

upstream/debian-unstable/man3/d2i_PrivateKey.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
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 3SSL"
58 .TH D2I_PRIVATEKEY 3SSL 2026-04-07 3.6.2 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,
66 i2d_PKCS8PrivateKey, i2d_PublicKey, i2d_KeyParams, i2d_KeyParams_bio,
67 d2i_PrivateKey_ex_bio, d2i_PrivateKey_bio, d2i_PrivateKey_ex_fp,
68 d2i_PrivateKey_fp, d2i_KeyParams_bio, i2d_PrivateKey_bio, 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_PKCS8PrivateKey(const EVP_PKEY *a, unsigned char **pp);
92 \& int i2d_PublicKey(const EVP_PKEY *a, unsigned char **pp);
93 \& int i2d_KeyParams(const EVP_PKEY *a, unsigned char **pp);
94 \& int i2d_KeyParams_bio(BIO *bp, const EVP_PKEY *pkey);
95 \& EVP_PKEY *d2i_KeyParams_bio(int type, EVP_PKEY **a, BIO *in);
96 \&
97 \&
98 \& #include <openssl/x509.h>
99 \&
100 \& EVP_PKEY *d2i_PrivateKey_ex_bio(BIO *bp, EVP_PKEY **a, OSSL_LIB_CTX *libctx,
101 \& const char *propq);
102 \& EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a);
103 \& EVP_PKEY *d2i_PrivateKey_ex_fp(FILE *fp, EVP_PKEY **a, OSSL_LIB_CTX *libctx,
104 \& const char *propq);
105 \& EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a);
106 \&
107 \& int i2d_PrivateKey_bio(BIO *bp, const EVP_PKEY *pkey);
108 \& int i2d_PrivateKey_fp(FILE *fp, const EVP_PKEY *pkey);
109 .Ve
110 .SH DESCRIPTION
111 .IX Header "DESCRIPTION"
112 \&\fBd2i_PrivateKey_ex()\fR decodes a private key using algorithm \fItype\fR. It attempts
113 to use any key-specific format or PKCS#8 unencrypted PrivateKeyInfo format.
114 The \fItype\fR parameter should be a public key algorithm constant such as
115 \&\fBEVP_PKEY_RSA\fR. An error occurs if the decoded key does not match \fItype\fR. Some
116 private key decoding implementations may use cryptographic algorithms (for
117 example to automatically derive the public key if it is not explicitly
118 included in the encoding). In this case the supplied library context \fIlibctx\fR
119 and property query string \fIpropq\fR are used.
120 If successful and the \fIa\fR parameter is not NULL the function assigns the
121 returned \fBEVP_PKEY\fR structure pointer to \fI*a\fR, overwriting any previous value.
122 .PP
123 \&\fBd2i_PrivateKey()\fR does the same as \fBd2i_PrivateKey_ex()\fR except that the default
124 library context and property query string are used.
125 \&\fBd2i_PublicKey()\fR does the same for public keys.
126 \&\fBd2i_KeyParams()\fR does the same for key parameters.
127 .PP
128 The \fBd2i_PrivateKey_ex_bio()\fR and \fBd2i_PrivateKey_bio()\fR functions are similar to
129 \&\fBd2i_PrivateKey_ex()\fR and \fBd2i_PrivateKey()\fR respectively except that they decode
130 the data read from the given BIO. The \fBd2i_PrivateKey_ex_fp()\fR and
131 \&\fBd2i_PrivateKey_fp()\fR functions are the same except that they read the data from
132 the given FILE.
133 .PP
134 \&\fBd2i_AutoPrivateKey_ex()\fR and \fBd2i_AutoPrivateKey()\fR are similar to
135 \&\fBd2i_PrivateKey_ex()\fR and \fBd2i_PrivateKey()\fR respectively except that they attempt
136 to automatically detect the private key format.
137 .PP
138 \&\fBi2d_PrivateKey()\fR encodes \fIa\fR. It uses a key specific format or, if none is
139 defined for that key type, PKCS#8 unencrypted PrivateKeyInfo format.
140 \&\fBi2d_PKCS8PrivateKey()\fR does the same using only the PKCS#8 unencrypted
141 PrivateKeyInfo format.
142 \&\fBi2d_PublicKey()\fR does the same for public keys.
143 \&\fBi2d_KeyParams()\fR does the same for key parameters.
144 These functions are similar to the \fBd2i_X509()\fR functions; see \fBd2i_X509\fR\|(3).
145 \&\fBi2d_PrivateKey_bio()\fR and \fBi2d_PrivateKey_fp()\fR do the same thing except that they
146 encode to a \fBBIO\fR or \fBFILE\fR respectively. Again, these work similarly to the
147 functions described in \fBd2i_X509\fR\|(3).
148 .SH NOTES
149 .IX Header "NOTES"
150 All the functions that operate on data in memory update the data pointer \fI*pp\fR
151 after a successful operation, just like the other d2i and i2d functions;
152 see \fBd2i_X509\fR\|(3).
153 .PP
154 All these functions use DER format and unencrypted keys. Applications wishing
155 to encrypt or decrypt private keys should use other functions such as
156 \&\fBd2i_PKCS8PrivateKey()\fR instead.
157 .PP
158 To decode a key with type \fBEVP_PKEY_EC\fR, \fBd2i_PublicKey()\fR requires \fI*a\fR to be
159 a non-NULL EVP_PKEY structure assigned an EC_KEY structure referencing the proper
160 EC_GROUP.
161 .SH "RETURN VALUES"
162 .IX Header "RETURN VALUES"
163 The \fBd2i_PrivateKey_ex()\fR, \fBd2i_PrivateKey()\fR, \fBd2i_AutoPrivateKey_ex()\fR,
164 \&\fBd2i_AutoPrivateKey()\fR, \fBd2i_PrivateKey_ex_bio()\fR, \fBd2i_PrivateKey_bio()\fR,
165 \&\fBd2i_PrivateKey_ex_fp()\fR, \fBd2i_PrivateKey_fp()\fR, \fBd2i_PublicKey()\fR, \fBd2i_KeyParams()\fR
166 and \fBd2i_KeyParams_bio()\fR functions return a valid \fBEVP_PKEY\fR structure or NULL if
167 an error occurs. The error code can be obtained by calling \fBERR_get_error\fR\|(3).
168 .PP
169 \&\fBi2d_PrivateKey()\fR, \fBi2d_PKCS8PrivateKey()\fR, \fBi2d_PublicKey()\fR and \fBi2d_KeyParams()\fR
170 return the number of bytes successfully encoded or a negative value if an error
171 occurs. The error code can be obtained by calling \fBERR_get_error\fR\|(3).
172 .PP
173 \&\fBi2d_PrivateKey_bio()\fR, \fBi2d_PrivateKey_fp()\fR and \fBi2d_KeyParams_bio()\fR return 1 if
174 successfully encoded or zero if an error occurs.
175 .SH "SEE ALSO"
176 .IX Header "SEE ALSO"
177 \&\fBcrypto\fR\|(7),
178 \&\fBd2i_PKCS8PrivateKey_bio\fR\|(3)
179 .SH HISTORY
180 .IX Header "HISTORY"
181 \&\fBd2i_PrivateKey_ex()\fR, \fBd2i_PrivateKey_ex_bio()\fR, \fBd2i_PrivateKey_ex_fp()\fR, and
182 \&\fBd2i_AutoPrivateKey_ex()\fR were added in OpenSSL 3.0.
183 .PP
184 \&\fBi2d_PKCS8PrivateKey()\fR was added in OpenSSL 3.6.
185 .SH COPYRIGHT
186 .IX Header "COPYRIGHT"
187 Copyright 2017\-2025 The OpenSSL Project Authors. All Rights Reserved.
188 .PP
189 Licensed under the Apache License 2.0 (the "License"). You may not use
190 this file except in compliance with the License. You can obtain a copy
191 in the file LICENSE in the source distribution or at
192 <https://www.openssl.org/source/license.html>.