CMS_ENCRYPTEDDATA_ENCRYPT(3ossl)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’… CMS_EncryptedData_encrypt πŸ’…

okay so bestie, welcome to CMS_ENCRYPTEDDATA_ENCRYPT(3ossl) β€” yes that's the whole title, it's giving "my name is my entire resume" energy, and it lives in the 3ossl section of the manual. this one's all about wrapping your data up in a CMS EncryptedData situation, and honestly? it slaps. let's get into it πŸŽ€


✨ NAME ✨

CMS_EncryptedData_encrypt_ex, CMS_EncryptedData_encrypt β€” the two functions that create a CMS EncryptedData. that's it, that's the whole job, and they do it flawlessly πŸ’–


✨ 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);

like, look at those signatures. gorgeous. no notes. πŸ‘‘


🌸 DESCRIPTION 🌸

so CMS_EncryptedData_encrypt_ex() builds you a CMS_ContentInfo structure whose type is NID_pkcs7_encrypted. very demure, very pkcs7.

  • in β€” a BIO holding the data you wanna encrypt. that's your payload, bestie 🫢
  • cipher β€” the cipher you're encrypting with
  • key β€” the encryption key, and it's keylen bytes long, no cap

the library context libctx and the property query propq get used when the function is retrieving algorithms from providers β€” so that's how it knows where to go shopping for its crypto πŸ’…

flags is a little grab-bag of optional flags, and the ones supported are CMS_DETACHED, CMS_STREAM and CMS_PARTIAL ✨

internally, CMS_final() gets called unless CMS_STREAM and/or CMS_PARTIAL is specified. so those two are lowkey the "i'll finish it myself, thanks" flags 😌

⚠️ important vibe check: the algorithm you pass in the cipher parameter must support ASN1 encoding of its parameters. and AEAD cipher algorithms? not supported. like, at all. don't even try it πŸ™ˆ

when you're done with the CMS_ContentInfo structure, you can free it with CMS_ContentInfo_free(3) β€” clean up after yourself, main character energy 🌈

and CMS_EncryptedData_encrypt() is basically the chill twin of CMS_EncryptedData_encrypt_ex(): same thing, except it uses default values of NULL for the library context libctx and the property query propq. defaults, but make it fashion πŸ’œ


πŸ”₯ RETURN VALUES πŸ”₯

if the allocation fails, CMS_EncryptedData_encrypt_ex() and CMS_EncryptedData_encrypt() return NULL and set an error code that you can grab with ERR_get_error(3). sad girl hours 😭

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


πŸ¦‹ SEE ALSO πŸ¦‹

ERR_get_error(3), CMS_final(3), CMS_EncryptedData_decrypt(3)

(the decrypt one is right there if you need to go the other direction, iykyk 🧚)


⭐ HISTORY ⭐

the CMS_EncryptedData_encrypt_ex() method was added in OpenSSL 3.0. a relatively recent icon, honestly πŸ‘‘


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


and that's the whole page, bestie πŸ“ no cap. this lil doc is from OpenSSL 3.5.6, dated 2026-04-07, filed under CMS_ENCRYPTEDDATA_ENCRYPT(3ossl) β€” go encrypt something gorgeous, mwah πŸ’–πŸ’…

πŸ“¦ where this page comes from