CMS_ENCRYPTEDDATA_ENCRYPT(3ossl)

πŸ’– CMS_ENCRYPTEDDATA_ENCRYPT πŸ’–

okay bestie, pull up a chair, because today we're talking about CMS_EncryptedData_encrypt_ex and CMS_EncryptedData_encrypt β€” the OpenSSL 3 functions that literally create a CMS EncryptedData for you. yeah. main character energy fr. 🌸


✨ NAME ✨

CMS_EncryptedData_encrypt_ex, CMS_EncryptedData_encrypt β€” they create a CMS EncryptedData structure. that's the whole job. iconic. πŸ’…


πŸŽ€ 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);

no cap, those signatures are exact, copy them character for character or the compiler WILL be petty about it. 😭


πŸ¦‹ DESCRIPTION πŸ¦‹

so CMS_EncryptedData_encrypt_ex() builds you a CMS_ContentInfo structure whose type is NID_pkcs7_encrypted. slay.

  • in is a BIO holding the data you wanna encrypt πŸ”₯
  • cipher is the cipher you're encrypting with
  • key is the encryption key, and it's keylen bytes long
  • the library context libctx and the property query propq get used when retrieving algorithms from providers (iykyk)
  • flags is a set of optional flags, and girl, there are three of them

the flags field supports these options: CMS_DETACHED, CMS_STREAM and CMS_PARTIAL. πŸ’–

lowkey important: internally CMS_final() gets called unless CMS_STREAM and/or CMS_PARTIAL is specified. so if you pass those, you're on your own for finalizing. just so you know. πŸ‘‘

and now for the part that ruins the vibe:

the algorithm you pass in the cipher parameter must support ASN1 encoding of its parameters. and AEAD cipher algorithms? not supported. periodt. πŸ’€

when you're done with it, you can free the CMS_ContentInfo structure with CMS_ContentInfo_free(3). be a good citizen and clean up after yourself. 🧚

CMS_EncryptedData_encrypt() is the same vibe as CMS_EncryptedData_encrypt_ex() except it just uses default values of NULL for the library context libctx and the property query propq. easy peasy. 🌈


⭐ RETURN VALUES ⭐

if the allocation fails, both CMS_EncryptedData_encrypt_ex() and CMS_EncryptedData_encrypt() return NULL and set an error code that you can grab with ERR_get_error(3). πŸ™ˆ

otherwise? they return a pointer to the newly allocated structure. ate. πŸ‘‘


🌟 SEE ALSO 🌟

go read those next, bestie, they're the supporting cast. 🫢


πŸ’œ HISTORY πŸ’œ

the CMS_EncryptedData_encrypt_ex() method was added in OpenSSL 3.0. glow up. ✨


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>.


okay that's the whole page, bestie, you're officially fluent πŸ’… and hey β€” this was OpenSSL 3.5.9, dated 2026-09-29, from the CMS_ENCRYPTEDDATA_ENCRYPT(3ossl) manual. go encrypt something cute. mwah. πŸŽ€πŸ’–πŸ¦‹

πŸ“¦ where this page comes from