CMS_ENCRYPT(3)
π CMS_ENCRYPT(3) π
okay bestie, welcome to the Library Functions Manual entry for CMS_encrypt β yes, the header says CMS_ENCRYPT(3), and we are folding that manual-name energy right in here. β¨
πΈ NAME πΈ
CMS_encrypt β create a CMS EnvelopedData structure. That's the whole assignment. π
β¨ SYNOPSIS β¨
call it like this, bestie:
library βlibcryptoβ #include <openssl/cms.h>
CMS_ContentInfo *
CMS_encrypt(STACK_OF(X509) *certificates, BIO *in,
const EVP_CIPHER *cipher, unsigned int flags);
π DESCRIPTION π
CMS_encrypt() creates a CMS EnvelopedData structure, encrypting the content provided by in. It's giving βwrap it up and keep it safeβ energy. π
The recipient certificates are added as KeyTransRecipientInfo structures by calling CMS_add1_recipient_cert(3) internally. Only certificates carrying RSA, Diffie-Hellman or EC keys are supported by this function. The certificates argument can be set to NULL if the CMS_PARTIAL flag is set and recipients are added later using CMS_add1_recipient_cert(3) or CMS_add0_recipient_key(3). iykyk. π¦
cipher is the symmetric cipher to use. It must support ASN.1 encoding of its parameters. EVP_des_ede3_cbc(3) (triple DES) is the algorithm of choice for S/MIME use because most clients support it. yes, triple DES is out here being the popular one β periodt. π
Many browsers implement a βsign and encryptβ 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 BIO and passing it to CMS_encrypt(). literally iconic. π₯
The following flags can be passed in the flags parameter:
CMS_TEXTβ MIME headers for typetext/plainare prepended to the data. cute little header moment. πCMS_BINARYβ Do not translate the supplied content into MIME canonical format even though that is required by the S/MIME specifications. This option should be used if the supplied data is in binary format. Otherwise, the translation will corrupt it. IfCMS_BINARYis set, thenCMS_TEXTis ignored. β οΈ no cap, this one matters.CMS_USE_KEYIDβ Use the subject key identifier value to identify recipient certificates. An error occurs if all recipient certificates do not have a subject key identifier extension. By default, issuer name and serial number are used instead. πCMS_STREAMβ Return a partialCMS_ContentInfostructure suitable for streaming I/O: no data is read from the BIOin. Several functions includingSMIME_write_CMS(3),i2d_CMS_bio_stream(3), orPEM_write_bio_CMS_stream(3)can be used to finalize the structure. Alternatively, finalization can be performed by obtaining the streaming ASN1 BIO directly usingBIO_new_CMS(3). Outputting the content of the returnedCMS_ContentInfostructure via a function that does not properly finalize it will give unpredictable results. π bestie, finalize it properly or chaos.CMS_PARTIALβ Return a partialCMS_ContentInfostructure to which additional recipients and attributes can be added before finalization. build-a-bear but make it crypto. π§ΈCMS_DETACHEDβ Omit the data being encrypted from theCMS_ContentInfostructure. This is rarely used in practice and is not supported bySMIME_write_CMS(3). rare and not supported β noted. π
π RETURN VALUES π
CMS_encrypt() returns either a CMS_ContentInfo structure or NULL if an error occurred. The error can be obtained from ERR_get_error(3). so if it's NULL, go ask ERR_get_error(3) what happened. π«Ά
π SEE ALSO π
go read these too, bestie:
β STANDARDS β
RFC 5652: Cryptographic Message Syntax (CMS)
- section 6.1:
EnvelopedDataType - section 6.2.1:
KeyTransRecipientInfoType
π¦ HISTORY π¦
CMS_encrypt() first appeared in OpenSSL 0.9.8h and has been available since OpenBSD 6.7.
The CMS_STREAM flag first appeared in OpenSSL 1.0.0.
source/version: Debian Β· date: June 8, 2025 Β· CMS_ENCRYPT(3) β bye bestie, go encrypt something slay π
π«Άβ¨
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2008 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms