SMIME_WRITE_PKCS7(3ossl)
β¨ SMIME_WRITE_PKCS7 β¨
okay bestie, so this is SMIME_write_PKCS7(3ossl) from the OpenSSL fam π β it's the glow-up function that takes your PKCS#7 structure and dresses it up all pretty in S/MIME format. no cap.
πΈ NAME πΈ
SMIME_write_PKCS7 β convert PKCS#7 structure to S/MIME format π
π SYNOPSIS π
#include <openssl/pkcs7.h>
int SMIME_write_PKCS7(BIO *out, PKCS7 *p7, BIO *data, int flags);
π¦ DESCRIPTION π¦
SMIME_write_PKCS7() is literally the MIME-header fairy π§ β it adds all the appropriate MIME headers onto a PKCS#7 structure so you get a whole S/MIME message out the other side.
Here's the vibe check on the args:
outβ theBIOyou're writing the data to. your lil output stream, periodt.p7β the appropriatePKCS7structure. the main character of this whole operation πdataβ if streaming is enabled, the content must be supplied here in this argument. no skipping it, bestie.flagsβ an optional set of flags. optional! but iconic.
π NOTES π
the following flags can be passed in the flags parameter. let's go through them one by one, i got you π«Ά
PKCS7_DETACHEDβ if this is set, then cleartext signing will be used. this option only makes sense forsignedDatawherePKCS7_DETACHEDis also set whenPKCS7_sign()is also called. like, they gotta match, it's giving coordinated outfit energy πPKCS7_TEXTβ if this flag is set, MIME headers for typetext/plainare added to the content. this only makes sense ifPKCS7_DETACHEDis also set. lowkey a package deal.PKCS7_STREAMβ if this is set, streaming is performed. this flag should only be set ifPKCS7_STREAMwas also set in the previous call toPKCS7_sign()orPKCS7_encrypt(). do not freestyle this one, fr fr.
okay important note: if cleartext signing is being used andPKCS7_STREAMis not set, then the data must be read twice β once to compute the signature inPKCS7_sign(), and once to output the S/MIME message. yeah. two reads. it's a whole thing π
and if streaming is performed, the content is output in BER format using indefinite length constructed encoding β except in the case of signed data with detached content, where the content is absent and DER format is used instead. little exception, huge difference β¨
π BUGS π
not me having to tell you this but β SMIME_write_PKCS7() always base64 encodes PKCS#7 structures. there should be an option to disable this. there isn't. so. π
β RETURN VALUES β
SMIME_write_PKCS7() returns 1 for success or 0 for failure. that's it, that's the whole thing. simple queen behavior π
π SEE ALSO π
π COPYRIGHT π
Copyright 2002-2016 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 ate that π
this was SMIME_WRITE_PKCS7(3ossl) β version 3.5.9, dated 2026-09-29, straight from OpenSSL. mwah, go forth and MIME πβ¨
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms