xref: /freebsd/crypto/openssl/doc/man3/PKCS7_encrypt.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5*b077aed3SPierre ProncheryPKCS7_encrypt_ex, PKCS7_encrypt
6*b077aed3SPierre Pronchery- create a PKCS#7 envelopedData structure
7e71b7053SJung-uk Kim
8e71b7053SJung-uk Kim=head1 SYNOPSIS
9e71b7053SJung-uk Kim
10e71b7053SJung-uk Kim #include <openssl/pkcs7.h>
11e71b7053SJung-uk Kim
12*b077aed3SPierre Pronchery PKCS7 *PKCS7_encrypt_ex(STACK_OF(X509) *certs, BIO *in,
13*b077aed3SPierre Pronchery                         const EVP_CIPHER *cipher, int flags,
14*b077aed3SPierre Pronchery                         OSSL_LIB_CTX *libctx, const char *propq);
15e71b7053SJung-uk Kim PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
16e71b7053SJung-uk Kim                      int flags);
17e71b7053SJung-uk Kim
18e71b7053SJung-uk Kim=head1 DESCRIPTION
19e71b7053SJung-uk Kim
20*b077aed3SPierre ProncheryPKCS7_encrypt_ex() creates and returns a PKCS#7 envelopedData structure.
21*b077aed3SPierre ProncheryI<certs> is a list of recipient certificates. I<in> is the content to be
22*b077aed3SPierre Proncheryencrypted. I<cipher> is the symmetric cipher to use. I<flags> is an optional set
23*b077aed3SPierre Proncheryof flags. The library context I<libctx> and the property query I<propq> are used
24*b077aed3SPierre Proncherywhen retrieving algorithms from providers.
25e71b7053SJung-uk Kim
26e71b7053SJung-uk KimOnly RSA keys are supported in PKCS#7 and envelopedData so the recipient
27e71b7053SJung-uk Kimcertificates supplied to this function must all contain RSA public keys, though
28e71b7053SJung-uk Kimthey do not have to be signed using the RSA algorithm.
29e71b7053SJung-uk Kim
30e71b7053SJung-uk KimEVP_des_ede3_cbc() (triple DES) is the algorithm of choice for S/MIME use
31e71b7053SJung-uk Kimbecause most clients will support it.
32e71b7053SJung-uk Kim
33e71b7053SJung-uk KimSome old "export grade" clients may only support weak encryption using 40 or 64
34e71b7053SJung-uk Kimbit RC2. These can be used by passing EVP_rc2_40_cbc() and EVP_rc2_64_cbc()
35e71b7053SJung-uk Kimrespectively.
36e71b7053SJung-uk Kim
37e71b7053SJung-uk KimThe algorithm passed in the B<cipher> parameter must support ASN1 encoding of
38e71b7053SJung-uk Kimits parameters.
39e71b7053SJung-uk Kim
40e71b7053SJung-uk KimMany browsers implement a "sign and encrypt" option which is simply an S/MIME
41e71b7053SJung-uk KimenvelopedData containing an S/MIME signed message. This can be readily produced
42e71b7053SJung-uk Kimby storing the S/MIME signed message in a memory BIO and passing it to
43e71b7053SJung-uk KimPKCS7_encrypt().
44e71b7053SJung-uk Kim
45e71b7053SJung-uk KimThe following flags can be passed in the B<flags> parameter.
46e71b7053SJung-uk Kim
47e71b7053SJung-uk KimIf the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are
48e71b7053SJung-uk Kimprepended to the data.
49e71b7053SJung-uk Kim
50e71b7053SJung-uk KimNormally the supplied content is translated into MIME canonical format (as
51e71b7053SJung-uk Kimrequired by the S/MIME specifications) if B<PKCS7_BINARY> is set no translation
52e71b7053SJung-uk Kimoccurs. This option should be used if the supplied data is in binary format
53e71b7053SJung-uk Kimotherwise the translation will corrupt it. If B<PKCS7_BINARY> is set then
54e71b7053SJung-uk KimB<PKCS7_TEXT> is ignored.
55e71b7053SJung-uk Kim
56e71b7053SJung-uk KimIf the B<PKCS7_STREAM> flag is set a partial B<PKCS7> structure is output
57e71b7053SJung-uk Kimsuitable for streaming I/O: no data is read from the BIO B<in>.
58e71b7053SJung-uk Kim
59e71b7053SJung-uk KimIf the flag B<PKCS7_STREAM> is set the returned B<PKCS7> structure is B<not>
60e71b7053SJung-uk Kimcomplete and outputting its contents via a function that does not
61e71b7053SJung-uk Kimproperly finalize the B<PKCS7> structure will give unpredictable
62e71b7053SJung-uk Kimresults.
63e71b7053SJung-uk Kim
64e71b7053SJung-uk KimSeveral functions including SMIME_write_PKCS7(), i2d_PKCS7_bio_stream(),
65e71b7053SJung-uk KimPEM_write_bio_PKCS7_stream() finalize the structure. Alternatively finalization
66e71b7053SJung-uk Kimcan be performed by obtaining the streaming ASN1 B<BIO> directly using
67e71b7053SJung-uk KimBIO_new_PKCS7().
68e71b7053SJung-uk Kim
69*b077aed3SPierre ProncheryPKCS7_encrypt() is similar to PKCS7_encrypt_ex() but uses default
70*b077aed3SPierre Proncheryvalues of NULL for the library context I<libctx> and the property query I<propq>.
71*b077aed3SPierre Pronchery
72e71b7053SJung-uk Kim=head1 RETURN VALUES
73e71b7053SJung-uk Kim
74*b077aed3SPierre ProncheryPKCS7_encrypt_ex() and PKCS7_encrypt() return either a PKCS7 structure
75*b077aed3SPierre Proncheryor NULL if an error occurred. The error can be obtained from ERR_get_error(3).
76e71b7053SJung-uk Kim
77e71b7053SJung-uk Kim=head1 SEE ALSO
78e71b7053SJung-uk Kim
79e71b7053SJung-uk KimL<ERR_get_error(3)>, L<PKCS7_decrypt(3)>
80e71b7053SJung-uk Kim
81e71b7053SJung-uk Kim=head1 HISTORY
82e71b7053SJung-uk Kim
83*b077aed3SPierre ProncheryThe function PKCS7_encrypt_ex() was added in OpenSSL 3.0.
84*b077aed3SPierre Pronchery
85e71b7053SJung-uk KimThe B<PKCS7_STREAM> flag was added in OpenSSL 1.0.0.
86e71b7053SJung-uk Kim
87e71b7053SJung-uk Kim=head1 COPYRIGHT
88e71b7053SJung-uk Kim
89*b077aed3SPierre ProncheryCopyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
90e71b7053SJung-uk Kim
91*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
92e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
93e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
94e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
95e71b7053SJung-uk Kim
96e71b7053SJung-uk Kim=cut
97