| 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 "OSSL_ENCODER_CTX_NEW_FOR_PKEY 3SSL" |
| 58 |
.TH OSSL_ENCODER_CTX_NEW_FOR_PKEY 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 |
OSSL_ENCODER_CTX_new_for_pkey, |
| 65 |
OSSL_ENCODER_CTX_set_cipher, |
| 66 |
OSSL_ENCODER_CTX_set_passphrase, |
| 67 |
OSSL_ENCODER_CTX_set_pem_password_cb, |
| 68 |
OSSL_ENCODER_CTX_set_passphrase_cb, |
| 69 |
OSSL_ENCODER_CTX_set_passphrase_ui |
| 70 |
\&\- Encoder routines to encode EVP_PKEYs |
| 71 |
.SH SYNOPSIS |
| 72 |
.IX Header "SYNOPSIS" |
| 73 |
.Vb 1 |
| 74 |
\& #include <openssl/encoder.h> |
| 75 |
\& |
| 76 |
\& OSSL_ENCODER_CTX * |
| 77 |
\& OSSL_ENCODER_CTX_new_for_pkey(const EVP_PKEY *pkey, int selection, |
| 78 |
\& const char *output_type, |
| 79 |
\& const char *output_structure, |
| 80 |
\& const char *propquery); |
| 81 |
\& |
| 82 |
\& int OSSL_ENCODER_CTX_set_cipher(OSSL_ENCODER_CTX *ctx, |
| 83 |
\& const char *cipher_name, |
| 84 |
\& const char *propquery); |
| 85 |
\& int OSSL_ENCODER_CTX_set_passphrase(OSSL_ENCODER_CTX *ctx, |
| 86 |
\& const unsigned char *kstr, |
| 87 |
\& size_t klen); |
| 88 |
\& int OSSL_ENCODER_CTX_set_pem_password_cb(OSSL_ENCODER_CTX *ctx, |
| 89 |
\& pem_password_cb *cb, void *cbarg); |
| 90 |
\& int OSSL_ENCODER_CTX_set_passphrase_ui(OSSL_ENCODER_CTX *ctx, |
| 91 |
\& const UI_METHOD *ui_method, |
| 92 |
\& void *ui_data); |
| 93 |
\& int OSSL_ENCODER_CTX_set_passphrase_cb(OSSL_ENCODER_CTX *ctx, |
| 94 |
\& OSSL_PASSPHRASE_CALLBACK *cb, |
| 95 |
\& void *cbarg); |
| 96 |
.Ve |
| 97 |
.SH DESCRIPTION |
| 98 |
.IX Header "DESCRIPTION" |
| 99 |
\&\fBOSSL_ENCODER_CTX_new_for_pkey()\fR is a utility function that creates a |
| 100 |
\&\fBOSSL_ENCODER_CTX\fR, finds all applicable encoder implementations and sets |
| 101 |
them up, so almost all the caller has to do next is call functions like |
| 102 |
\&\fBOSSL_ENCODER_to_bio\fR\|(3). \fIoutput_type\fR determines the final output |
| 103 |
encoding, and \fIselection\fR can be used to select what parts of the \fIpkey\fR |
| 104 |
should be included in the output. \fIoutput_type\fR is further discussed in |
| 105 |
"Output types" below, and \fIselection\fR is further described in |
| 106 |
"Selections". |
| 107 |
.PP |
| 108 |
Internally, \fBOSSL_ENCODER_CTX_new_for_pkey()\fR uses the names from the |
| 109 |
\&\fBEVP_KEYMGMT\fR\|(3) implementation associated with \fIpkey\fR to build a list of |
| 110 |
applicable encoder implementations that are used to process the \fIpkey\fR into |
| 111 |
the encoding named by \fIoutput_type\fR, with the outermost structure named by |
| 112 |
\&\fIoutput_structure\fR if that's relevant. All these implementations are |
| 113 |
implicitly fetched, with \fIpropquery\fR for finer selection. |
| 114 |
.PP |
| 115 |
If no suitable encoder implementation is found, |
| 116 |
\&\fBOSSL_ENCODER_CTX_new_for_pkey()\fR still creates a \fBOSSL_ENCODER_CTX\fR, but |
| 117 |
with no associated encoder (\fBOSSL_ENCODER_CTX_get_num_encoders\fR\|(3) returns |
| 118 |
zero). This helps the caller to distinguish between an error when creating |
| 119 |
the \fBOSSL_ENCODER_CTX\fR and missing encoder implementation, and allows it to |
| 120 |
act accordingly. |
| 121 |
.PP |
| 122 |
Note that \fBOSSL_ENCODER_CTX_new_for_pkey()\fR finalises the OSSL_ENCODER_CTX; |
| 123 |
after that the OSSL_ENCODER_CTX_set_* and OSSL_ENCODER_CTX_add_* functions |
| 124 |
described in \fBOSSL_ENCODER_CTX\fR\|(3) shouldn't be called. |
| 125 |
.PP |
| 126 |
\&\fBOSSL_ENCODER_CTX_set_cipher()\fR tells the implementation what cipher |
| 127 |
should be used to encrypt encoded keys. The cipher is given by |
| 128 |
name \fIcipher_name\fR. The interpretation of that \fIcipher_name\fR is |
| 129 |
implementation dependent. The implementation may implement the cipher |
| 130 |
directly itself or by other implementations, or it may choose to fetch |
| 131 |
it. If the implementation supports fetching the cipher, then it may |
| 132 |
use \fIpropquery\fR as properties to be queried for when fetching. |
| 133 |
\&\fIcipher_name\fR may also be NULL, which will result in unencrypted |
| 134 |
encoding. |
| 135 |
.PP |
| 136 |
\&\fBOSSL_ENCODER_CTX_set_passphrase()\fR gives the implementation a |
| 137 |
pass phrase to use when encrypting the encoded private key. |
| 138 |
Alternatively, a pass phrase callback may be specified with the |
| 139 |
following functions. |
| 140 |
.PP |
| 141 |
\&\fBOSSL_ENCODER_CTX_set_pem_password_cb()\fR, \fBOSSL_ENCODER_CTX_set_passphrase_ui()\fR |
| 142 |
and \fBOSSL_ENCODER_CTX_set_passphrase_cb()\fR sets up a callback method that the |
| 143 |
implementation can use to prompt for a pass phrase, giving the caller the |
| 144 |
choice of preferred pass phrase callback form. These are called indirectly, |
| 145 |
through an internal \fBOSSL_PASSPHRASE_CALLBACK\fR\|(3) function. |
| 146 |
.SS "Output types" |
| 147 |
.IX Subsection "Output types" |
| 148 |
The possible \fBEVP_PKEY\fR output types depends on the available |
| 149 |
implementations. |
| 150 |
.PP |
| 151 |
OpenSSL has built in implementations for the following output types: |
| 152 |
.ie n .IP """TEXT""" 4 |
| 153 |
.el .IP \f(CWTEXT\fR 4 |
| 154 |
.IX Item "TEXT" |
| 155 |
The output is a human readable description of the key. |
| 156 |
\&\fBEVP_PKEY_print_private\fR\|(3), \fBEVP_PKEY_print_public\fR\|(3) and |
| 157 |
\&\fBEVP_PKEY_print_params\fR\|(3) use this for their output. |
| 158 |
.ie n .IP """DER""" 4 |
| 159 |
.el .IP \f(CWDER\fR 4 |
| 160 |
.IX Item "DER" |
| 161 |
The output is the DER encoding of the \fIselection\fR of the \fIpkey\fR. |
| 162 |
.ie n .IP """PEM""" 4 |
| 163 |
.el .IP \f(CWPEM\fR 4 |
| 164 |
.IX Item "PEM" |
| 165 |
The output is the \fIselection\fR of the \fIpkey\fR in PEM format. |
| 166 |
.SS Selections |
| 167 |
.IX Subsection "Selections" |
| 168 |
\&\fIselection\fR can be any one of the values described in |
| 169 |
"Selections" in \fBEVP_PKEY_fromdata\fR\|(3). |
| 170 |
.PP |
| 171 |
These are only 'hints' since the encoder implementations are free to |
| 172 |
determine what makes sense to include in the output, and this may depend on |
| 173 |
the desired output. For example, an EC key in a PKCS#8 structure doesn't |
| 174 |
usually include the public key. |
| 175 |
.SH "RETURN VALUES" |
| 176 |
.IX Header "RETURN VALUES" |
| 177 |
\&\fBOSSL_ENCODER_CTX_new_for_pkey()\fR returns a pointer to an \fBOSSL_ENCODER_CTX\fR, |
| 178 |
or NULL if it couldn't be created. |
| 179 |
.PP |
| 180 |
\&\fBOSSL_ENCODER_CTX_set_cipher()\fR, \fBOSSL_ENCODER_CTX_set_passphrase()\fR, |
| 181 |
\&\fBOSSL_ENCODER_CTX_set_pem_password_cb()\fR, \fBOSSL_ENCODER_CTX_set_passphrase_ui()\fR |
| 182 |
and \fBOSSL_ENCODER_CTX_set_passphrase_cb()\fR all return 1 on success, or 0 on |
| 183 |
failure. |
| 184 |
.SH "SEE ALSO" |
| 185 |
.IX Header "SEE ALSO" |
| 186 |
\&\fBprovider\fR\|(7), \fBOSSL_ENCODER\fR\|(3), \fBOSSL_ENCODER_CTX\fR\|(3) |
| 187 |
.SH HISTORY |
| 188 |
.IX Header "HISTORY" |
| 189 |
The functions described here were added in OpenSSL 3.0. |
| 190 |
.SH COPYRIGHT |
| 191 |
.IX Header "COPYRIGHT" |
| 192 |
Copyright 2019\-2022 The OpenSSL Project Authors. All Rights Reserved. |
| 193 |
.PP |
| 194 |
Licensed under the Apache License 2.0 (the "License"). You may not use |
| 195 |
this file except in compliance with the License. You can obtain a copy |
| 196 |
in the file LICENSE in the source distribution or at |
| 197 |
<https://www.openssl.org/source/license.html>. |