CMS_ENCRYPTEDDATA_ENCRYPT(3ossl)
π 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β aBIOholding the data you wanna encrypt. that's your payload, bestie π«Άcipherβ the cipher you're encrypting withkeyβ the encryption key, and it'skeylenbytes 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 π
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
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms