PKCS7_encrypt(3) OpenSSL PKCS7_encrypt(3) NNAAMMEE PKCS7_encrypt - create a PKCS#7 envelopedData structure SSYYNNOOPPSSIISS #include PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher, int flags); DDEESSCCRRIIPPTTIIOONN _P_K_C_S_7___e_n_c_r_y_p_t_(_) creates and returns a PKCS#7 envelopedData structure. cceerrttss is a list of recipient certificates. iinn is the content to be encrypted. cciipphheerr is the symmetric cipher to use. ffllaaggss is an optional set of flags. NNOOTTEESS Only RSA keys are supported in PKCS#7 and envelopedData so the recipi- ent certificates supplied to this function must all contain RSA public keys, though they do not have to be signed using the RSA algorithm. _E_V_P___d_e_s___e_d_e_3___c_b_c_(_) (triple DES) is the algorithm of choice for S/MIME use because most clients will support it. Some old "export grade" clients may only support weak encryption using 40 or 64 bit RC2. These can be used by passing _E_V_P___r_c_2___4_0___c_b_c_(_) and _E_V_P___r_c_2___6_4___c_b_c_(_) respectively. The algorithm passed in the cciipphheerr parameter must support ASN1 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 _P_K_C_S_7___e_n_c_r_y_p_t_(_). The following flags can be passed in the ffllaaggss parameter. If the PPKKCCSS77__TTEEXXTT flag is set MIME headers for type tteexxtt//ppllaaiinn are prepended to the data. Normally the supplied content is translated into MIME canonical format (as required by the S/MIME specifications) if PPKKCCSS77__BBIINNAARRYY 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 PPKKCCSS77__BBIINNAARRYY is set then PPKKCCSS77__TTEEXXTT is ignored. If the PPKKCCSS77__SSTTRREEAAMM flag is set a partial PPKKCCSS77 structure is output suitable for streaming I/O: no data is read from the BIO iinn. NNOOTTEESS If the flag PPKKCCSS77__SSTTRREEAAMM is set the returned PPKKCCSS77 structure is nnoott complete and outputting its contents via a function that does not prop- erly finalize the PPKKCCSS77 structure will give unpredictable results. Several functions including _S_M_I_M_E___w_r_i_t_e___P_K_C_S_7_(_), _i_2_d___P_K_C_S_7___b_i_o___s_t_r_e_a_m_(_), _P_E_M___w_r_i_t_e___b_i_o___P_K_C_S_7___s_t_r_e_a_m_(_) finalize the structure. Alternatively finalization can be performed by obtaining the streaming ASN1 BBIIOO directly using _B_I_O___n_e_w___P_K_C_S_7_(_). RREETTUURRNN VVAALLUUEESS _P_K_C_S_7___e_n_c_r_y_p_t_(_) returns either a PKCS7 structure or NULL if an error occurred. The error can be obtained from _E_R_R___g_e_t___e_r_r_o_r(3). SSEEEE AALLSSOO _E_R_R___g_e_t___e_r_r_o_r(3), _P_K_C_S_7___d_e_c_r_y_p_t(3) HHIISSTTOORRYY _P_K_C_S_7___d_e_c_r_y_p_t_(_) was added to OpenSSL 0.9.5 The PPKKCCSS77__SSTTRREEAAMM flag was first supported in OpenSSL 1.0.0. 1.0.2u 2019-12-20 PKCS7_encrypt(3)