CMS_ENCRYPTEDDATA_ENCRYPT(3SSL)
π CMS_ENCRYPTEDDATA_ENCRYPT π
hey bestie πΈ so this is a page from the OpenSSL manual, section 3SSL, and it's all about two little functions that make you a CMS EncryptedData blob: CMS_EncryptedData_encrypt_ex and CMS_EncryptedData_encrypt. it's giving "wrap your secrets in a cute lil envelope" energy, and honestly? obsessed. π
β¨ NAME β¨
CMS_EncryptedData_encrypt_ex, CMS_EncryptedData_encrypt β Create CMS EncryptedData π
π SYNOPSIS π
okay so here's the tea, verbatim, no cap:
#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);
π DESCRIPTION π
so CMS_EncryptedData_encrypt_ex() builds you a CMS_ContentInfo structure and gives it the type NID_pkcs7_encrypted β that's the whole point, that's the vibe. π₯
inis aBIOholding the data you wanna encrypt πcipheris the cipher you're encrypting it withkeyis the encryption key, and it'skeylenbytes long π- the library context
libctx(that's thectxargument in the synopsis, iykyk) and the property querypropqget used when pulling algorithms out of providers β¨ flagsis a set of optional flags β the fun little toggles
π¦ the flags π¦
the flags field supports these options:
CMS_DETACHEDCMS_STREAMCMS_PARTIAL
and here's the important bit: internally CMS_final() gets called unless CMS_STREAM and/or CMS_PARTIAL is specified. so like, no CMS_STREAM, no CMS_PARTIAL, CMS_final() shows up to the party whether you asked or not π
π the cipher tea π
the algorithm you pass in the cipher parameter must support ASN1 encoding of its parameters. like, that's the requirement, no negotiating. π
and AEAD cipher algorithms are not supported β periodt. not a thing here, don't even try it.
also, when you're done with yourCMS_ContentInfostructure, free it withCMS_ContentInfo_free(3). be a responsible main character π«Ά
π and the diet version π
CMS_EncryptedData_encrypt() is literally the same as CMS_EncryptedData_encrypt_ex(), except it uses default values of NULL for the library context libctx and the property query propq. so if you don't care about that stuff, take the shortcut bestie, it's iconic. β¨
π RETURN VALUES π
- if the allocation fails,
CMS_EncryptedData_encrypt_ex()andCMS_EncryptedData_encrypt()returnNULLand set an error code that you can grab withERR_get_error(3)π - otherwise they return a pointer to the freshly allocated structure β slay π
πΈ SEE ALSO πΈ
(go read those too, they're the extended universe π§)
β HISTORY β
CMS_EncryptedData_encrypt_ex() was added in OpenSSL 3.0. so it's a newer model, not an OG. still ate tho. π
π COPYRIGHT π
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, you're fully caught up π this was OpenSSL 4.0.3, dated 2026-09-29, from the CMS_ENCRYPTEDDATA_ENCRYPT(3SSL) page β congrats on finishing, you absolute legend, go encrypt something cute πβ¨
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms