1e1051a39Sopenharmony_ci=pod
2e1051a39Sopenharmony_ci
3e1051a39Sopenharmony_ci=head1 NAME
4e1051a39Sopenharmony_ci
5e1051a39Sopenharmony_ciPKCS7_encrypt_ex, PKCS7_encrypt
6e1051a39Sopenharmony_ci- create a PKCS#7 envelopedData structure
7e1051a39Sopenharmony_ci
8e1051a39Sopenharmony_ci=head1 SYNOPSIS
9e1051a39Sopenharmony_ci
10e1051a39Sopenharmony_ci #include <openssl/pkcs7.h>
11e1051a39Sopenharmony_ci
12e1051a39Sopenharmony_ci PKCS7 *PKCS7_encrypt_ex(STACK_OF(X509) *certs, BIO *in,
13e1051a39Sopenharmony_ci                         const EVP_CIPHER *cipher, int flags,
14e1051a39Sopenharmony_ci                         OSSL_LIB_CTX *libctx, const char *propq);
15e1051a39Sopenharmony_ci PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
16e1051a39Sopenharmony_ci                      int flags);
17e1051a39Sopenharmony_ci
18e1051a39Sopenharmony_ci=head1 DESCRIPTION
19e1051a39Sopenharmony_ci
20e1051a39Sopenharmony_ciPKCS7_encrypt_ex() creates and returns a PKCS#7 envelopedData structure.
21e1051a39Sopenharmony_ciI<certs> is a list of recipient certificates. I<in> is the content to be
22e1051a39Sopenharmony_ciencrypted. I<cipher> is the symmetric cipher to use. I<flags> is an optional set
23e1051a39Sopenharmony_ciof flags. The library context I<libctx> and the property query I<propq> are used
24e1051a39Sopenharmony_ciwhen retrieving algorithms from providers.
25e1051a39Sopenharmony_ci
26e1051a39Sopenharmony_ciOnly RSA keys are supported in PKCS#7 and envelopedData so the recipient
27e1051a39Sopenharmony_cicertificates supplied to this function must all contain RSA public keys, though
28e1051a39Sopenharmony_cithey do not have to be signed using the RSA algorithm.
29e1051a39Sopenharmony_ci
30e1051a39Sopenharmony_ciEVP_des_ede3_cbc() (triple DES) is the algorithm of choice for S/MIME use
31e1051a39Sopenharmony_cibecause most clients will support it.
32e1051a39Sopenharmony_ci
33e1051a39Sopenharmony_ciSome old "export grade" clients may only support weak encryption using 40 or 64
34e1051a39Sopenharmony_cibit RC2. These can be used by passing EVP_rc2_40_cbc() and EVP_rc2_64_cbc()
35e1051a39Sopenharmony_cirespectively.
36e1051a39Sopenharmony_ci
37e1051a39Sopenharmony_ciThe algorithm passed in the B<cipher> parameter must support ASN1 encoding of
38e1051a39Sopenharmony_ciits parameters.
39e1051a39Sopenharmony_ci
40e1051a39Sopenharmony_ciMany browsers implement a "sign and encrypt" option which is simply an S/MIME
41e1051a39Sopenharmony_cienvelopedData containing an S/MIME signed message. This can be readily produced
42e1051a39Sopenharmony_ciby storing the S/MIME signed message in a memory BIO and passing it to
43e1051a39Sopenharmony_ciPKCS7_encrypt().
44e1051a39Sopenharmony_ci
45e1051a39Sopenharmony_ciThe following flags can be passed in the B<flags> parameter.
46e1051a39Sopenharmony_ci
47e1051a39Sopenharmony_ciIf the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are
48e1051a39Sopenharmony_ciprepended to the data.
49e1051a39Sopenharmony_ci
50e1051a39Sopenharmony_ciNormally the supplied content is translated into MIME canonical format (as
51e1051a39Sopenharmony_cirequired by the S/MIME specifications) if B<PKCS7_BINARY> is set no translation
52e1051a39Sopenharmony_cioccurs. This option should be used if the supplied data is in binary format
53e1051a39Sopenharmony_ciotherwise the translation will corrupt it. If B<PKCS7_BINARY> is set then
54e1051a39Sopenharmony_ciB<PKCS7_TEXT> is ignored.
55e1051a39Sopenharmony_ci
56e1051a39Sopenharmony_ciIf the B<PKCS7_STREAM> flag is set a partial B<PKCS7> structure is output
57e1051a39Sopenharmony_cisuitable for streaming I/O: no data is read from the BIO B<in>.
58e1051a39Sopenharmony_ci
59e1051a39Sopenharmony_ciIf the flag B<PKCS7_STREAM> is set the returned B<PKCS7> structure is B<not>
60e1051a39Sopenharmony_cicomplete and outputting its contents via a function that does not
61e1051a39Sopenharmony_ciproperly finalize the B<PKCS7> structure will give unpredictable
62e1051a39Sopenharmony_ciresults.
63e1051a39Sopenharmony_ci
64e1051a39Sopenharmony_ciSeveral functions including SMIME_write_PKCS7(), i2d_PKCS7_bio_stream(),
65e1051a39Sopenharmony_ciPEM_write_bio_PKCS7_stream() finalize the structure. Alternatively finalization
66e1051a39Sopenharmony_cican be performed by obtaining the streaming ASN1 B<BIO> directly using
67e1051a39Sopenharmony_ciBIO_new_PKCS7().
68e1051a39Sopenharmony_ci
69e1051a39Sopenharmony_ciPKCS7_encrypt() is similar to PKCS7_encrypt_ex() but uses default
70e1051a39Sopenharmony_civalues of NULL for the library context I<libctx> and the property query I<propq>.
71e1051a39Sopenharmony_ci
72e1051a39Sopenharmony_ci=head1 RETURN VALUES
73e1051a39Sopenharmony_ci
74e1051a39Sopenharmony_ciPKCS7_encrypt_ex() and PKCS7_encrypt() return either a PKCS7 structure
75e1051a39Sopenharmony_cior NULL if an error occurred. The error can be obtained from ERR_get_error(3).
76e1051a39Sopenharmony_ci
77e1051a39Sopenharmony_ci=head1 SEE ALSO
78e1051a39Sopenharmony_ci
79e1051a39Sopenharmony_ciL<ERR_get_error(3)>, L<PKCS7_decrypt(3)>
80e1051a39Sopenharmony_ci
81e1051a39Sopenharmony_ci=head1 HISTORY
82e1051a39Sopenharmony_ci
83e1051a39Sopenharmony_ciThe function PKCS7_encrypt_ex() was added in OpenSSL 3.0.
84e1051a39Sopenharmony_ci
85e1051a39Sopenharmony_ciThe B<PKCS7_STREAM> flag was added in OpenSSL 1.0.0.
86e1051a39Sopenharmony_ci
87e1051a39Sopenharmony_ci=head1 COPYRIGHT
88e1051a39Sopenharmony_ci
89e1051a39Sopenharmony_ciCopyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
90e1051a39Sopenharmony_ci
91e1051a39Sopenharmony_ciLicensed under the Apache License 2.0 (the "License").  You may not use
92e1051a39Sopenharmony_cithis file except in compliance with the License.  You can obtain a copy
93e1051a39Sopenharmony_ciin the file LICENSE in the source distribution or at
94e1051a39Sopenharmony_ciL<https://www.openssl.org/source/license.html>.
95e1051a39Sopenharmony_ci
96e1051a39Sopenharmony_ci=cut
97