| 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 "CMS_ENCRYPT 3SSL" |
| 58 |
.TH CMS_ENCRYPT 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 |
CMS_encrypt_ex, CMS_encrypt \- create a CMS envelopedData structure |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 1 |
| 68 |
\& #include <openssl/cms.h> |
| 69 |
\& |
| 70 |
\& CMS_ContentInfo *CMS_encrypt_ex(STACK_OF(X509) *certs, BIO *in, |
| 71 |
\& const EVP_CIPHER *cipher, unsigned int flags, |
| 72 |
\& OSSL_LIB_CTX *libctx, const char *propq); |
| 73 |
\& CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *in, |
| 74 |
\& const EVP_CIPHER *cipher, unsigned int flags); |
| 75 |
.Ve |
| 76 |
.SH DESCRIPTION |
| 77 |
.IX Header "DESCRIPTION" |
| 78 |
\&\fBCMS_encrypt_ex()\fR creates and returns a CMS EnvelopedData or |
| 79 |
AuthEnvelopedData structure. \fIcerts\fR is a list of recipient certificates. |
| 80 |
\&\fIin\fR is the content to be encrypted. \fIcipher\fR is the symmetric cipher to use. |
| 81 |
\&\fIflags\fR is an optional set of flags. The library context \fIlibctx\fR and the |
| 82 |
property query \fIpropq\fR are used internally when retrieving algorithms from |
| 83 |
providers. |
| 84 |
.PP |
| 85 |
Only certificates carrying RSA, Diffie-Hellman or EC keys are supported by this |
| 86 |
function. |
| 87 |
.PP |
| 88 |
\&\fBEVP_des_ede3_cbc()\fR (triple DES) is the algorithm of choice for S/MIME use |
| 89 |
because most clients will support it. |
| 90 |
.PP |
| 91 |
The algorithm passed in the \fBcipher\fR parameter must support ASN1 encoding of |
| 92 |
its parameters. If the cipher mode is GCM, then an AuthEnvelopedData structure |
| 93 |
containing MAC is used. Otherwise an EnvelopedData structure is used. Currently |
| 94 |
the AES variants with GCM mode are the only supported AEAD algorithms. |
| 95 |
.PP |
| 96 |
Many browsers implement a "sign and encrypt" option which is simply an S/MIME |
| 97 |
envelopedData containing an S/MIME signed message. This can be readily produced |
| 98 |
by storing the S/MIME signed message in a memory BIO and passing it to |
| 99 |
\&\fBCMS_encrypt()\fR. |
| 100 |
.PP |
| 101 |
The following flags can be passed in the \fBflags\fR parameter. |
| 102 |
.PP |
| 103 |
If the \fBCMS_TEXT\fR flag is set MIME headers for type \fBtext/plain\fR are |
| 104 |
prepended to the data. |
| 105 |
.PP |
| 106 |
Normally the supplied content is translated into MIME canonical format (as |
| 107 |
required by the S/MIME specifications) if \fBCMS_BINARY\fR is set no translation |
| 108 |
occurs. This option should be used if the supplied data is in binary format |
| 109 |
otherwise the translation will corrupt it. If \fBCMS_BINARY\fR is set then |
| 110 |
\&\fBCMS_TEXT\fR is ignored. |
| 111 |
.PP |
| 112 |
OpenSSL will by default identify recipient certificates using issuer name |
| 113 |
and serial number. If \fBCMS_USE_KEYID\fR is set it will use the subject key |
| 114 |
identifier value instead. An error occurs if all recipient certificates do not |
| 115 |
have a subject key identifier extension. |
| 116 |
.PP |
| 117 |
If the \fBCMS_STREAM\fR flag is set a partial \fBCMS_ContentInfo\fR structure is |
| 118 |
returned suitable for streaming I/O: no data is read from the BIO \fBin\fR. |
| 119 |
.PP |
| 120 |
If the \fBCMS_PARTIAL\fR flag is set a partial \fBCMS_ContentInfo\fR structure is |
| 121 |
returned to which additional recipients and attributes can be added before |
| 122 |
finalization. |
| 123 |
.PP |
| 124 |
The data being encrypted is included in the CMS_ContentInfo structure, unless |
| 125 |
\&\fBCMS_DETACHED\fR is set in which case it is omitted. This is rarely used in |
| 126 |
practice and is not supported by \fBSMIME_write_CMS()\fR. |
| 127 |
.PP |
| 128 |
If the flag \fBCMS_STREAM\fR is set the returned \fBCMS_ContentInfo\fR structure is |
| 129 |
\&\fBnot\fR complete and outputting its contents via a function that does not |
| 130 |
properly finalize the \fBCMS_ContentInfo\fR structure will give unpredictable |
| 131 |
results. |
| 132 |
.PP |
| 133 |
Several functions including \fBSMIME_write_CMS()\fR, \fBi2d_CMS_bio_stream()\fR, |
| 134 |
\&\fBPEM_write_bio_CMS_stream()\fR finalize the structure. Alternatively finalization |
| 135 |
can be performed by obtaining the streaming ASN1 \fBBIO\fR directly using |
| 136 |
\&\fBBIO_new_CMS()\fR. |
| 137 |
.PP |
| 138 |
The recipients specified in \fBcerts\fR use a CMS KeyTransRecipientInfo info |
| 139 |
structure. KEKRecipientInfo is also supported using the flag \fBCMS_PARTIAL\fR |
| 140 |
and \fBCMS_add0_recipient_key()\fR. KEMRecipientInfo is also supported using the |
| 141 |
flag \fBCMS_PARTIAL\fR and \fBCMS_add1_recipient()\fR. |
| 142 |
.PP |
| 143 |
The parameter \fBcerts\fR may be NULL if \fBCMS_PARTIAL\fR is set and recipients |
| 144 |
are added later using \fBCMS_add1_recipient()\fR or \fBCMS_add1_recipient_cert()\fR with |
| 145 |
\&\fBCMS_add0_recipient_key()\fR. |
| 146 |
.PP |
| 147 |
\&\fBCMS_encrypt()\fR is similar to \fBCMS_encrypt_ex()\fR but uses default values |
| 148 |
of NULL for the library context \fIlibctx\fR and the property query \fIpropq\fR. |
| 149 |
.SH "RETURN VALUES" |
| 150 |
.IX Header "RETURN VALUES" |
| 151 |
\&\fBCMS_encrypt_ex()\fR and \fBCMS_encrypt()\fR return either a CMS_ContentInfo |
| 152 |
structure or NULL if an error occurred. The error can be obtained from |
| 153 |
\&\fBERR_get_error\fR\|(3). |
| 154 |
.SH "SEE ALSO" |
| 155 |
.IX Header "SEE ALSO" |
| 156 |
\&\fBERR_get_error\fR\|(3), \fBCMS_decrypt\fR\|(3) |
| 157 |
.SH HISTORY |
| 158 |
.IX Header "HISTORY" |
| 159 |
The function \fBCMS_encrypt_ex()\fR was added in OpenSSL 3.0. |
| 160 |
.PP |
| 161 |
The \fBCMS_STREAM\fR flag was first supported in OpenSSL 1.0.0. |
| 162 |
.SH COPYRIGHT |
| 163 |
.IX Header "COPYRIGHT" |
| 164 |
Copyright 2008\-2025 The OpenSSL Project Authors. All Rights Reserved. |
| 165 |
.PP |
| 166 |
Licensed under the Apache License 2.0 (the "License"). You may not use |
| 167 |
this file except in compliance with the License. You can obtain a copy |
| 168 |
in the file LICENSE in the source distribution or at |
| 169 |
<https://www.openssl.org/source/license.html>. |