xref: /freebsd/secure/lib/libcrypto/man/man3/CMS_encrypt.3 (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)

Standard preamble:
========================================================================
..
..
.. Set up some character translations and predefined strings. \*(-- will
give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
double quote, and \*(R" will give a right double quote. \*(C+ will
give a nicer C++. Capital omega is used to do unbreakable dashes and
therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
nothing in troff, for use with C<>.
.tr \(*W- . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\}
Escape single quotes in literal strings from groff's Unicode transform.

If the F register is >0, we'll generate index entries on stderr for
titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
entries marked with X<> in POD. Of course, you'll have to process the
output yourself in some meaningful fashion.

Avoid warning from groff about undefined register 'F'.
.. .nr rF 0 . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] .\} . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents . \" corrections for vroff . \" for low resolution devices (crt and lpr) \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} ========================================================================

Title "CMS_ENCRYPT 3ossl"
CMS_ENCRYPT 3ossl "2023-09-19" "3.0.11" "OpenSSL"
For nroff, turn off justification. Always turn off hyphenation; it makes
way too many mistakes in technical documents.
"NAME"
CMS_encrypt_ex, CMS_encrypt - create a CMS envelopedData structure
"SYNOPSIS"
Header "SYNOPSIS" .Vb 1 #include <openssl/cms.h> \& CMS_ContentInfo *CMS_encrypt_ex(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher, unsigned int flags, OSSL_LIB_CTX *libctx, const char *propq); CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher, unsigned int flags); .Ve
"DESCRIPTION"
Header "DESCRIPTION" \fBCMS_encrypt_ex() creates and returns a \s-1CMS\s0 EnvelopedData or AuthEnvelopedData structure. certs is a list of recipient certificates. \fIin is the content to be encrypted. cipher is the symmetric cipher to use. \fIflags is an optional set of flags. The library context libctx and the property query propq are used internally when retrieving algorithms from providers.

Only certificates carrying \s-1RSA,\s0 Diffie-Hellman or \s-1EC\s0 keys are supported by this function.

\fBEVP_des_ede3_cbc() (triple \s-1DES\s0) is the algorithm of choice for S/MIME use because most clients will support it.

The algorithm passed in the cipher parameter must support \s-1ASN1\s0 encoding of its parameters. If the cipher mode is \s-1GCM,\s0 then an AuthEnvelopedData structure containing \s-1MAC\s0 is used. Otherwise an EnvelopedData structure is used. Currently the \s-1AES\s0 variants with \s-1GCM\s0 mode are the only supported \s-1AEAD\s0 algorithms.

Many browsers implement a \*(L"sign and encrypt\*(R" option which is simply an S/MIME envelopedData containing an S/MIME signed message. This can be readily produced by storing the S/MIME signed message in a memory \s-1BIO\s0 and passing it to \fBCMS_encrypt().

The following flags can be passed in the flags parameter.

If the \s-1CMS_TEXT\s0 flag is set \s-1MIME\s0 headers for type text/plain are prepended to the data.

Normally the supplied content is translated into \s-1MIME\s0 canonical format (as required by the S/MIME specifications) if \s-1CMS_BINARY\s0 is set no translation occurs. This option should be used if the supplied data is in binary format otherwise the translation will corrupt it. If \s-1CMS_BINARY\s0 is set then \fB\s-1CMS_TEXT\s0 is ignored.

OpenSSL will by default identify recipient certificates using issuer name and serial number. If \s-1CMS_USE_KEYID\s0 is set it will use the subject key identifier value instead. An error occurs if all recipient certificates do not have a subject key identifier extension.

If the \s-1CMS_STREAM\s0 flag is set a partial CMS_ContentInfo structure is returned suitable for streaming I/O: no data is read from the \s-1BIO\s0 in.

If the \s-1CMS_PARTIAL\s0 flag is set a partial CMS_ContentInfo structure is returned to which additional recipients and attributes can be added before finalization.

The data being encrypted is included in the CMS_ContentInfo structure, unless \fB\s-1CMS_DETACHED\s0 is set in which case it is omitted. This is rarely used in practice and is not supported by SMIME_write_CMS().

If the flag \s-1CMS_STREAM\s0 is set the returned CMS_ContentInfo structure is \fBnot complete and outputting its contents via a function that does not properly finalize the CMS_ContentInfo structure will give unpredictable results.

Several functions including SMIME_write_CMS(), i2d_CMS_bio_stream(), \fBPEM_write_bio_CMS_stream() finalize the structure. Alternatively finalization can be performed by obtaining the streaming \s-1ASN1\s0 \s-1BIO\s0 directly using \fBBIO_new_CMS().

The recipients specified in certs use a \s-1CMS\s0 KeyTransRecipientInfo info structure. KEKRecipientInfo is also supported using the flag \s-1CMS_PARTIAL\s0 and CMS_add0_recipient_key().

The parameter certs may be \s-1NULL\s0 if \s-1CMS_PARTIAL\s0 is set and recipients added later using CMS_add1_recipient_cert() or CMS_add0_recipient_key().

\fBCMS_encrypt() is similar to CMS_encrypt_ex() but uses default values of \s-1NULL\s0 for the library context libctx and the property query propq.

"RETURN VALUES"
Header "RETURN VALUES" \fBCMS_encrypt_ex() and CMS_encrypt() return either a CMS_ContentInfo structure or \s-1NULL\s0 if an error occurred. The error can be obtained from \fBERR_get_error\|(3).
"SEE ALSO"
Header "SEE ALSO" \fBERR_get_error\|(3), CMS_decrypt\|(3)
"HISTORY"
Header "HISTORY" The function CMS_encrypt_ex() was added in OpenSSL 3.0.

The \s-1CMS_STREAM\s0 flag was first supported in OpenSSL 1.0.0.

"COPYRIGHT"
Header "COPYRIGHT" Copyright 2008-2020 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use this file except in compliance with the License. You can obtain a copy in the file \s-1LICENSE\s0 in the source distribution or at <https://www.openssl.org/source/license.html>.