CMS_encrypt.3ossl 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "CMS_ENCRYPT 3ossl"
  58. .TH CMS_ENCRYPT 3ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. CMS_encrypt_ex, CMS_encrypt \- create a CMS envelopedData structure
  65. .SH SYNOPSIS
  66. .IX Header "SYNOPSIS"
  67. .Vb 1
  68. \& #include <openssl/cms.h>
  69. \&
  70. \& CMS_ContentInfo *CMS_encrypt_ex(STACK_OF(X509) *certs, BIO *in,
  71. \& const EVP_CIPHER *cipher, unsigned int flags,
  72. \& OSSL_LIB_CTX *libctx, const char *propq);
  73. \& CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *in,
  74. \& const EVP_CIPHER *cipher, unsigned int flags);
  75. .Ve
  76. .SH DESCRIPTION
  77. .IX Header "DESCRIPTION"
  78. \&\fBCMS_encrypt_ex()\fR creates and returns a CMS EnvelopedData or
  79. AuthEnvelopedData structure. \fIcerts\fR is a list of recipient certificates.
  80. \&\fIin\fR is the content to be encrypted. \fIcipher\fR is the symmetric cipher to use.
  81. \&\fIflags\fR is an optional set of flags. The library context \fIlibctx\fR and the
  82. property query \fIpropq\fR are used internally when retrieving algorithms from
  83. providers.
  84. .PP
  85. Only certificates carrying RSA, Diffie-Hellman or EC keys are supported by this
  86. function.
  87. .PP
  88. \&\fBEVP_des_ede3_cbc()\fR (triple DES) is the algorithm of choice for S/MIME use
  89. because most clients will support it.
  90. .PP
  91. The algorithm passed in the \fBcipher\fR parameter must support ASN1 encoding of
  92. its parameters. If the cipher mode is GCM, then an AuthEnvelopedData structure
  93. containing MAC is used. Otherwise an EnvelopedData structure is used. Currently
  94. the AES variants with GCM mode are the only supported AEAD algorithms.
  95. .PP
  96. Many browsers implement a "sign and encrypt" option which is simply an S/MIME
  97. envelopedData containing an S/MIME signed message. This can be readily produced
  98. by storing the S/MIME signed message in a memory BIO and passing it to
  99. \&\fBCMS_encrypt()\fR.
  100. .PP
  101. The following flags can be passed in the \fBflags\fR parameter.
  102. .PP
  103. If the \fBCMS_TEXT\fR flag is set MIME headers for type \fBtext/plain\fR are
  104. prepended to the data.
  105. .PP
  106. Normally the supplied content is translated into MIME canonical format (as
  107. required by the S/MIME specifications) if \fBCMS_BINARY\fR is set no translation
  108. occurs. This option should be used if the supplied data is in binary format
  109. otherwise the translation will corrupt it. If \fBCMS_BINARY\fR is set then
  110. \&\fBCMS_TEXT\fR is ignored.
  111. .PP
  112. OpenSSL will by default identify recipient certificates using issuer name
  113. and serial number. If \fBCMS_USE_KEYID\fR is set it will use the subject key
  114. identifier value instead. An error occurs if all recipient certificates do not
  115. have a subject key identifier extension.
  116. .PP
  117. If the \fBCMS_STREAM\fR flag is set a partial \fBCMS_ContentInfo\fR structure is
  118. returned suitable for streaming I/O: no data is read from the BIO \fBin\fR.
  119. .PP
  120. If the \fBCMS_PARTIAL\fR flag is set a partial \fBCMS_ContentInfo\fR structure is
  121. returned to which additional recipients and attributes can be added before
  122. finalization.
  123. .PP
  124. The data being encrypted is included in the CMS_ContentInfo structure, unless
  125. \&\fBCMS_DETACHED\fR is set in which case it is omitted. This is rarely used in
  126. practice and is not supported by \fBSMIME_write_CMS()\fR.
  127. .PP
  128. If the flag \fBCMS_STREAM\fR is set the returned \fBCMS_ContentInfo\fR structure is
  129. \&\fBnot\fR complete and outputting its contents via a function that does not
  130. properly finalize the \fBCMS_ContentInfo\fR structure will give unpredictable
  131. results.
  132. .PP
  133. Several functions including \fBSMIME_write_CMS()\fR, \fBi2d_CMS_bio_stream()\fR,
  134. \&\fBPEM_write_bio_CMS_stream()\fR finalize the structure. Alternatively finalization
  135. can be performed by obtaining the streaming ASN1 \fBBIO\fR directly using
  136. \&\fBBIO_new_CMS()\fR.
  137. .PP
  138. The recipients specified in \fBcerts\fR use a CMS KeyTransRecipientInfo info
  139. structure. KEKRecipientInfo is also supported using the flag \fBCMS_PARTIAL\fR
  140. and \fBCMS_add0_recipient_key()\fR.
  141. .PP
  142. The parameter \fBcerts\fR may be NULL if \fBCMS_PARTIAL\fR is set and recipients
  143. added later using \fBCMS_add1_recipient_cert()\fR or \fBCMS_add0_recipient_key()\fR.
  144. .PP
  145. \&\fBCMS_encrypt()\fR is similar to \fBCMS_encrypt_ex()\fR but uses default values
  146. of NULL for the library context \fIlibctx\fR and the property query \fIpropq\fR.
  147. .SH "RETURN VALUES"
  148. .IX Header "RETURN VALUES"
  149. \&\fBCMS_encrypt_ex()\fR and \fBCMS_encrypt()\fR return either a CMS_ContentInfo
  150. structure or NULL if an error occurred. The error can be obtained from
  151. \&\fBERR_get_error\fR\|(3).
  152. .SH "SEE ALSO"
  153. .IX Header "SEE ALSO"
  154. \&\fBERR_get_error\fR\|(3), \fBCMS_decrypt\fR\|(3)
  155. .SH HISTORY
  156. .IX Header "HISTORY"
  157. The function \fBCMS_encrypt_ex()\fR was added in OpenSSL 3.0.
  158. .PP
  159. The \fBCMS_STREAM\fR flag was first supported in OpenSSL 1.0.0.
  160. .SH COPYRIGHT
  161. .IX Header "COPYRIGHT"
  162. Copyright 2008\-2020 The OpenSSL Project Authors. All Rights Reserved.
  163. .PP
  164. Licensed under the Apache License 2.0 (the "License"). You may not use
  165. this file except in compliance with the License. You can obtain a copy
  166. in the file LICENSE in the source distribution or at
  167. <https://www.openssl.org/source/license.html>.