xref: /netbsd-src/crypto/external/bsd/openssl/dist/doc/man3/PKCS7_encrypt.pod (revision b0d1725196a7921d003d2c66a14f186abda4176b)
113d40330Schristos=pod
213d40330Schristos
313d40330Schristos=head1 NAME
413d40330Schristos
5*b0d17251SchristosPKCS7_encrypt_ex, PKCS7_encrypt
6*b0d17251Schristos- create a PKCS#7 envelopedData structure
713d40330Schristos
813d40330Schristos=head1 SYNOPSIS
913d40330Schristos
1013d40330Schristos #include <openssl/pkcs7.h>
1113d40330Schristos
12*b0d17251Schristos PKCS7 *PKCS7_encrypt_ex(STACK_OF(X509) *certs, BIO *in,
13*b0d17251Schristos                         const EVP_CIPHER *cipher, int flags,
14*b0d17251Schristos                         OSSL_LIB_CTX *libctx, const char *propq);
1513d40330Schristos PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
1613d40330Schristos                      int flags);
1713d40330Schristos
1813d40330Schristos=head1 DESCRIPTION
1913d40330Schristos
20*b0d17251SchristosPKCS7_encrypt_ex() creates and returns a PKCS#7 envelopedData structure.
21*b0d17251SchristosI<certs> is a list of recipient certificates. I<in> is the content to be
22*b0d17251Schristosencrypted. I<cipher> is the symmetric cipher to use. I<flags> is an optional set
23*b0d17251Schristosof flags. The library context I<libctx> and the property query I<propq> are used
24*b0d17251Schristoswhen retrieving algorithms from providers.
2513d40330Schristos
2613d40330SchristosOnly RSA keys are supported in PKCS#7 and envelopedData so the recipient
2713d40330Schristoscertificates supplied to this function must all contain RSA public keys, though
2813d40330Schristosthey do not have to be signed using the RSA algorithm.
2913d40330Schristos
3013d40330SchristosEVP_des_ede3_cbc() (triple DES) is the algorithm of choice for S/MIME use
3113d40330Schristosbecause most clients will support it.
3213d40330Schristos
3313d40330SchristosSome old "export grade" clients may only support weak encryption using 40 or 64
3413d40330Schristosbit RC2. These can be used by passing EVP_rc2_40_cbc() and EVP_rc2_64_cbc()
3513d40330Schristosrespectively.
3613d40330Schristos
3713d40330SchristosThe algorithm passed in the B<cipher> parameter must support ASN1 encoding of
3813d40330Schristosits parameters.
3913d40330Schristos
4013d40330SchristosMany browsers implement a "sign and encrypt" option which is simply an S/MIME
4113d40330SchristosenvelopedData containing an S/MIME signed message. This can be readily produced
4213d40330Schristosby storing the S/MIME signed message in a memory BIO and passing it to
4313d40330SchristosPKCS7_encrypt().
4413d40330Schristos
4513d40330SchristosThe following flags can be passed in the B<flags> parameter.
4613d40330Schristos
4713d40330SchristosIf the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are
4813d40330Schristosprepended to the data.
4913d40330Schristos
5013d40330SchristosNormally the supplied content is translated into MIME canonical format (as
5113d40330Schristosrequired by the S/MIME specifications) if B<PKCS7_BINARY> is set no translation
5213d40330Schristosoccurs. This option should be used if the supplied data is in binary format
5313d40330Schristosotherwise the translation will corrupt it. If B<PKCS7_BINARY> is set then
5413d40330SchristosB<PKCS7_TEXT> is ignored.
5513d40330Schristos
5613d40330SchristosIf the B<PKCS7_STREAM> flag is set a partial B<PKCS7> structure is output
5713d40330Schristossuitable for streaming I/O: no data is read from the BIO B<in>.
5813d40330Schristos
5913d40330SchristosIf the flag B<PKCS7_STREAM> is set the returned B<PKCS7> structure is B<not>
6013d40330Schristoscomplete and outputting its contents via a function that does not
6113d40330Schristosproperly finalize the B<PKCS7> structure will give unpredictable
6213d40330Schristosresults.
6313d40330Schristos
6413d40330SchristosSeveral functions including SMIME_write_PKCS7(), i2d_PKCS7_bio_stream(),
6513d40330SchristosPEM_write_bio_PKCS7_stream() finalize the structure. Alternatively finalization
6613d40330Schristoscan be performed by obtaining the streaming ASN1 B<BIO> directly using
6713d40330SchristosBIO_new_PKCS7().
6813d40330Schristos
69*b0d17251SchristosPKCS7_encrypt() is similar to PKCS7_encrypt_ex() but uses default
70*b0d17251Schristosvalues of NULL for the library context I<libctx> and the property query I<propq>.
71*b0d17251Schristos
7213d40330Schristos=head1 RETURN VALUES
7313d40330Schristos
74*b0d17251SchristosPKCS7_encrypt_ex() and PKCS7_encrypt() return either a PKCS7 structure
75*b0d17251Schristosor NULL if an error occurred. The error can be obtained from ERR_get_error(3).
7613d40330Schristos
7713d40330Schristos=head1 SEE ALSO
7813d40330Schristos
7913d40330SchristosL<ERR_get_error(3)>, L<PKCS7_decrypt(3)>
8013d40330Schristos
8113d40330Schristos=head1 HISTORY
8213d40330Schristos
83*b0d17251SchristosThe function PKCS7_encrypt_ex() was added in OpenSSL 3.0.
84*b0d17251Schristos
8513d40330SchristosThe B<PKCS7_STREAM> flag was added in OpenSSL 1.0.0.
8613d40330Schristos
8713d40330Schristos=head1 COPYRIGHT
8813d40330Schristos
89*b0d17251SchristosCopyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
9013d40330Schristos
91*b0d17251SchristosLicensed under the Apache License 2.0 (the "License").  You may not use
9213d40330Schristosthis file except in compliance with the License.  You can obtain a copy
9313d40330Schristosin the file LICENSE in the source distribution or at
9413d40330SchristosL<https://www.openssl.org/source/license.html>.
9513d40330Schristos
9613d40330Schristos=cut
97