1PKCS7_ENCRYPT(3) OpenSSL PKCS7_ENCRYPT(3)
2
3
4
6 PKCS7_encrypt - create a PKCS#7 envelopedData structure
7
9 #include <openssl/pkcs7.h>
10
11 PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
12 int flags);
13
15 PKCS7_encrypt() creates and returns a PKCS#7 envelopedData structure.
16 certs is a list of recipient certificates. in is the content to be
17 encrypted. cipher is the symmetric cipher to use. flags is an optional
18 set of flags.
19
21 Only RSA keys are supported in PKCS#7 and envelopedData so the
22 recipient certificates supplied to this function must all contain RSA
23 public keys, though they do not have to be signed using the RSA
24 algorithm.
25
26 EVP_des_ede3_cbc() (triple DES) is the algorithm of choice for S/MIME
27 use because most clients will support it.
28
29 Some old "export grade" clients may only support weak encryption using
30 40 or 64 bit RC2. These can be used by passing EVP_rc2_40_cbc() and
31 EVP_rc2_64_cbc() respectively.
32
33 The algorithm passed in the cipher parameter must support ASN1 encoding
34 of its parameters.
35
36 Many browsers implement a "sign and encrypt" option which is simply an
37 S/MIME envelopedData containing an S/MIME signed message. This can be
38 readily produced by storing the S/MIME signed message in a memory BIO
39 and passing it to PKCS7_encrypt().
40
41 The following flags can be passed in the flags parameter.
42
43 If the PKCS7_TEXT flag is set MIME headers for type text/plain are
44 prepended to the data.
45
46 Normally the supplied content is translated into MIME canonical format
47 (as required by the S/MIME specifications) if PKCS7_BINARY is set no
48 translation occurs. This option should be used if the supplied data is
49 in binary format otherwise the translation will corrupt it. If
50 PKCS7_BINARY is set then PKCS7_TEXT is ignored.
51
52 If the PKCS7_STREAM flag is set a partial PKCS7 structure is output
53 suitable for streaming I/O: no data is read from the BIO in.
54
56 If the flag PKCS7_STREAM is set the returned PKCS7 structure is not
57 complete and outputting its contents via a function that does not
58 properly finalize the PKCS7 structure will give unpredictable results.
59
60 Several functions including SMIME_write_PKCS7(),
61 i2d_PKCS7_bio_stream(), PEM_write_bio_PKCS7_stream() finalize the
62 structure. Alternatively finalization can be performed by obtaining the
63 streaming ASN1 BIO directly using BIO_new_PKCS7().
64
66 PKCS7_encrypt() returns either a PKCS7 structure or NULL if an error
67 occurred. The error can be obtained from ERR_get_error(3).
68
70 ERR_get_error(3), PKCS7_decrypt(3)
71
73 The PKCS7_STREAM flag was added in OpenSSL 1.0.0.
74
76 Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
77
78 Licensed under the OpenSSL license (the "License"). You may not use
79 this file except in compliance with the License. You can obtain a copy
80 in the file LICENSE in the source distribution or at
81 <https://www.openssl.org/source/license.html>.
82
83
84
851.1.1g 2020-04-23 PKCS7_ENCRYPT(3)