create a PKCS#7 envelopedData
*certs, BIO *in, const
EVP_CIPHER *cipher, int flags);
creates and returns a PKCS#7 envelopedData structure.
certs is a list of recipient certificates.
in is the content to be encrypted.
cipher is the symmetric cipher to use.
flags is an optional set of flags.
Only RSA keys are supported in PKCS#7 and envelopedData so the recipient certificates supplied to this function must all contain RSA public keys, though they do not have to be signed using the RSA algorithm.
The algorithm passed in the cipher parameter must support ASN.1 encoding of its parameters.
Many browsers implement a "sign and
encrypt" option which is simply an S/MIME envelopedData containing an
S/MIME signed message. This can be readily produced by storing the S/MIME
signed message in a memory BIO and passing it to
The following flags can be passed in the flags parameter.
PKCS7_TEXT flag is
set, MIME headers for type
prepended to the data.
Normally the supplied content is translated into MIME canonical
format (as required by the S/MIME specifications). If
PKCS7_BINARY is set, no translation occurs. This
option should be used if the supplied data is in binary format; otherwise,
the translation will corrupt it. If
PKCS7_TEXT is ignored.
PKCS7_STREAM flag is set, a partial
PKCS7 structure is output suitable for streaming I/O:
no data is read from in.
If the flag
PKCS7_STREAM is set,
the returned PKCS7 structure is
not complete and
outputting its contents via a function that does not properly finalize the
PKCS7 structure will give unpredictable results.
Several functions including
i2d_PKCS7_bio_stream(3) finalize the structure. Alternatively
finalization can be performed by obtaining the streaming ASN.1
BIO directly using
PKCS7_encrypt() returns either a
PKCS7 structure or
NULL if an
error occurred. The error can be obtained from
PKCS7_decrypt(3), PKCS7_final(3), PKCS7_new(3), PKCS7_sign(3)
PKCS7_encrypt() first appeared in OpenSSL
0.9.5 and has been available since OpenBSD 2.7.
PKCS7_STREAM flag was first supported
in OpenSSL 1.0.0.