CMS_ENCRYPTEDDATA_ENCRYPT(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’– CMS_EncryptedData_encrypt(3ossl) πŸ’–

okay so bestie, this is a page from the 3ossl manual set, and it's literally all about making a CMS EncryptedData thing. yes, we're doing crypto. no, you can't just vibe your way through it β€” but honestly? you're gonna slay this ✨


πŸŽ€ NAME πŸŽ€

CMS_EncryptedData_encrypt_ex, CMS_EncryptedData_encrypt β€” the two functions that create a CMS EncryptedData structure. like, they make it. that's the whole job 🫢


🌸 SYNOPSIS 🌸

#include <openssl/cms.h>

CMS_ContentInfo *CMS_EncryptedData_encrypt_ex(BIO *in,
                                              const EVP_CIPHER *cipher,
                                              const unsigned char *key,
                                              size_t keylen,
                                              unsigned int flags,
                                              OSSL_LIB_CTX *ctx,
                                              const char *propq);

CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in,
    const EVP_CIPHER *cipher, const unsigned char *key, size_t keylen,
    unsigned int flags);

look at those signatures. gorgeous. iconic. copy them exactly, i'm begging you πŸ’…


✨ DESCRIPTION ✨

CMS_EncryptedData_encrypt_ex() creates a CMS_ContentInfo structure with a type of NID_pkcs7_encrypted. and what does it put in there? your data, babe πŸ’–

in is a BIO containing the data you want to encrypt β€” using cipher and the encryption key key of size keylen bytes. that's the tea.

The library context libctx and the property query propq are used when retrieving algorithms from providers. (they're the ones doing the fetch, lowkey the real main characters here πŸ‘‘)

flags is a set of optional flags β€” hit the OPTIONS-ish part next:

  • The flags field supports the options CMS_DETACHED, CMS_STREAM and CMS_PARTIAL.
  • Internally CMS_final() is called unless CMS_STREAM and/or CMS_PARTIAL is specified. so like, know that. it matters 😭
⚠️ heads up: the algorithm you pass in the cipher parameter must support ASN1 encoding of its parameters. non-negotiable. no cap.

The CMS_ContentInfo structure can be freed using CMS_ContentInfo_free(3). please free it. don't be that person who leaks 🫢

CMS_EncryptedData_encrypt() is similar to CMS_EncryptedData_encrypt_ex() but uses default values of NULL for the library context libctx and the property query propq. so it's the chill, fewer-arguments version β€” fr fr, same energy, fewer params πŸ’…


πŸ’€ RETURN VALUES πŸ’€

If the allocation fails, CMS_EncryptedData_encrypt_ex() and CMS_EncryptedData_encrypt() return NULL and set an error code that can be obtained by ERR_get_error(3). (go get the error, bestie β€” it will tell you what happened πŸ‘€)

Otherwise they return a pointer to the newly allocated structure. slay ✨


πŸ¦‹ SEE ALSO πŸ¦‹

that's the friend group. go read all of them 🫢


⭐ HISTORY ⭐

The CMS_EncryptedData_encrypt_ex() method was added in OpenSSL 3.0. so yes, it's the newer one β€” the _ex at the end is giving "i have extra parameters and i'm proud of it" 🌈


Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.

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

like, read the license. it's not a suggestion, it's the rules πŸŽ€


and that's a wrap, bestie πŸ’œ β€” this page is from OpenSSL version 3.5.0, dated 2026-09-25, and it lives in the CMS_ENCRYPTEDDATA_ENCRYPT(3ossl) manual. go encrypt something cute βœ¨πŸŽ€πŸ’…

πŸ“¦ where this page comes from