SMIME_WRITE_PKCS7(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’Œ SMIME_write_PKCS7: the OpenSSL S/MIME glow-up πŸ’Œ

okay so bestie, welcome to the SMIME_WRITE_PKCS7(3ossl) manual page from OpenSSL. This is the one where your PKCS#7 structure gets cute little MIME headers and becomes an S/MIME message. No cap, it's giving β€œmake it email-ready” energy. πŸ’…


πŸ’– 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() adds the appropriate MIME headers to a PKCS#7 structure to produce an S/MIME message. It's literally the glow-up step. ✨

  • out is the BIO to write the data to.
  • p7 is the appropriate PKCS7 structure.
  • If streaming is enabled, then the content must be supplied in the data argument.
  • flags is an optional set of flags.

πŸŽ€ NOTES πŸŽ€

The following flags can be passed in the flags parameter:

  • PKCS7_DETACHED β€” if this is set, cleartext signing will be used. This option only makes sense for signedData where PKCS7_DETACHED is also set when PKCS7_sign() is also called.
  • PKCS7_TEXT β€” if this flag is set, MIME headers for type text/plain are added to the content. This only makes sense if PKCS7_DETACHED is also set.
  • PKCS7_STREAM β€” if this flag is set, streaming is performed. This flag should only be set if PKCS7_STREAM was also set in the previous call to PKCS7_sign() or PKCS7_encrypt().

If cleartext signing is being used and PKCS7_STREAM is not set, then the data must be read twice: once to compute the signature in PKCS7_sign() and once to output the S/MIME message. Yes, twice. The data is doing cardio. 😭

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.


πŸ’€ BUGS πŸ’€

SMIME_write_PKCS7() always base64 encodes PKCS#7 structures. There should be an option to disable this. That's the known ick. πŸ™ˆ


🫢 RETURN VALUES 🫢

SMIME_write_PKCS7() returns 1 for success or 0 for failure.


πŸ¦‹ SEE ALSO πŸ¦‹


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

mwah πŸ’‹ β€” OpenSSL 3.5.0, dated 2026-09-25, signing off. Stay iconic, bestie. πŸ’–

πŸ“¦ where this page comes from