PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/kdewebdev-3.5.10/php/function.openssl-pkcs7-encrypt.html

#
HTML | 277 lines | 271 code | 6 blank | 0 comment | 0 complexity | 3f7c8aaa4a48650ffdd6c23c6c06ce7a MD5 | raw file
Possible License(s): AGPL-1.0, CC-BY-SA-3.0, GPL-2.0
  1. <HTML
  2. ><HEAD
  3. ><TITLE
  4. >openssl_pkcs7_encrypt</TITLE
  5. ><META
  6. NAME="GENERATOR"
  7. CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
  8. REL="HOME"
  9. TITLE="PHP Manual"
  10. HREF="index.html"><LINK
  11. REL="UP"
  12. TITLE="OpenSSL functions"
  13. HREF="ref.openssl.html"><LINK
  14. REL="PREVIOUS"
  15. TITLE="openssl_pkcs7_decrypt"
  16. HREF="function.openssl-pkcs7-decrypt.html"><LINK
  17. REL="NEXT"
  18. TITLE="openssl_pkcs7_sign"
  19. HREF="function.openssl-pkcs7-sign.html"><META
  20. HTTP-EQUIV="Content-type"
  21. CONTENT="text/html; charset=ISO-8859-1"></HEAD
  22. ><BODY
  23. CLASS="refentry"
  24. BGCOLOR="#FFFFFF"
  25. TEXT="#000000"
  26. LINK="#0000FF"
  27. VLINK="#840084"
  28. ALINK="#0000FF"
  29. ><DIV
  30. CLASS="NAVHEADER"
  31. ><TABLE
  32. SUMMARY="Header navigation table"
  33. WIDTH="100%"
  34. BORDER="0"
  35. CELLPADDING="0"
  36. CELLSPACING="0"
  37. ><TR
  38. ><TH
  39. COLSPAN="3"
  40. ALIGN="center"
  41. >PHP Manual</TH
  42. ></TR
  43. ><TR
  44. ><TD
  45. WIDTH="10%"
  46. ALIGN="left"
  47. VALIGN="bottom"
  48. ><A
  49. HREF="function.openssl-pkcs7-decrypt.html"
  50. ACCESSKEY="P"
  51. >Prev</A
  52. ></TD
  53. ><TD
  54. WIDTH="80%"
  55. ALIGN="center"
  56. VALIGN="bottom"
  57. ></TD
  58. ><TD
  59. WIDTH="10%"
  60. ALIGN="right"
  61. VALIGN="bottom"
  62. ><A
  63. HREF="function.openssl-pkcs7-sign.html"
  64. ACCESSKEY="N"
  65. >Next</A
  66. ></TD
  67. ></TR
  68. ></TABLE
  69. ><HR
  70. ALIGN="LEFT"
  71. WIDTH="100%"></DIV
  72. ><H1
  73. ><A
  74. NAME="function.openssl-pkcs7-encrypt"
  75. ></A
  76. >openssl_pkcs7_encrypt</H1
  77. ><DIV
  78. CLASS="refnamediv"
  79. ><A
  80. NAME="AEN68248"
  81. ></A
  82. ><P
  83. > (PHP 4 &#62;= 4.0.6)</P
  84. >openssl_pkcs7_encrypt&nbsp;--&nbsp;Encrypt an S/MIME message</DIV
  85. ><DIV
  86. CLASS="refsect1"
  87. ><A
  88. NAME="AEN68251"
  89. ></A
  90. ><H2
  91. >Description</H2
  92. >bool <B
  93. CLASS="methodname"
  94. >openssl_pkcs7_encrypt</B
  95. > ( string infile, string outfile, mixed recipcerts, array headers [, long flags])<BR
  96. ></BR
  97. ><P
  98. >&#13; <B
  99. CLASS="function"
  100. >openssl_pkcs7_encrypt()</B
  101. > takes the contents of the
  102. file named <TT
  103. CLASS="parameter"
  104. ><I
  105. >infile</I
  106. ></TT
  107. > and encrypts them using an RC2
  108. 40-bit cipher so that they can only be read by the intended recipients
  109. specified by <TT
  110. CLASS="parameter"
  111. ><I
  112. >recipcerts</I
  113. ></TT
  114. >, which is either a
  115. lone X.509 certificate, or an array of X.509 certificates.
  116. <TT
  117. CLASS="parameter"
  118. ><I
  119. >headers</I
  120. ></TT
  121. > is an array of headers that
  122. will be prepended to the data after it has been encrypted.
  123. <TT
  124. CLASS="parameter"
  125. ><I
  126. >flags</I
  127. ></TT
  128. > can be used to specify options that affect
  129. the encoding process - see <A
  130. HREF="ref.openssl.html#openssl.pkcs7.flags"
  131. >PKCS7
  132. constants</A
  133. >.
  134. <TT
  135. CLASS="parameter"
  136. ><I
  137. >headers</I
  138. ></TT
  139. > can be either an associative array
  140. keyed by header name, or an indexed array, where each element contains
  141. a single header line.
  142. </P
  143. ><P
  144. >&#13; <TABLE
  145. WIDTH="100%"
  146. BORDER="0"
  147. CELLPADDING="0"
  148. CELLSPACING="0"
  149. CLASS="EXAMPLE"
  150. ><TR
  151. ><TD
  152. ><DIV
  153. CLASS="example"
  154. ><A
  155. NAME="AEN68280"
  156. ></A
  157. ><P
  158. ><B
  159. >Example 1. <B
  160. CLASS="function"
  161. >openssl_pkcs7_encrypt()</B
  162. > example</B
  163. ></P
  164. ><TABLE
  165. BORDER="0"
  166. BGCOLOR="#E0E0E0"
  167. CELLPADDING="5"
  168. ><TR
  169. ><TD
  170. ><PRE
  171. CLASS="php"
  172. >// the message you want to encrypt and send to your secret agent
  173. // in the field, known as nighthawk. You have his certificate
  174. // in the file nighthawk.pem
  175. $data = &#60;&#60;&#60;EOD
  176. Nighthawk,
  177. Top secret, for your eyes only!
  178. The enemy is closing in! Meet me at the cafe at 8.30am
  179. to collect your forged passport!
  180. HQ
  181. EOD;
  182. // load key
  183. $key = file_get_contents("nighthawk.pem");
  184. // save message to file
  185. $fp = fopen("msg.txt", "w");
  186. fwrite($fp, $data);
  187. fclose($fp);
  188. // encrypt it
  189. if (openssl_pkcs7_encrypt("msg.txt", "enc.txt", $key,
  190. array("To" =&#62; "nighthawk@example.com", // keyed syntax
  191. "From: HQ &#60;hq@example.com&#62;", // indexed syntax
  192. "Subject" =&#62; "Eyes only")))
  193. {
  194. // message encrypted - send it!
  195. exec(ini_get("sendmail_path") . " &#60; enc.txt");
  196. }</PRE
  197. ></TD
  198. ></TR
  199. ></TABLE
  200. ></DIV
  201. ></TD
  202. ></TR
  203. ></TABLE
  204. >
  205. </P
  206. ></DIV
  207. ><DIV
  208. CLASS="NAVFOOTER"
  209. ><HR
  210. ALIGN="LEFT"
  211. WIDTH="100%"><TABLE
  212. SUMMARY="Footer navigation table"
  213. WIDTH="100%"
  214. BORDER="0"
  215. CELLPADDING="0"
  216. CELLSPACING="0"
  217. ><TR
  218. ><TD
  219. WIDTH="33%"
  220. ALIGN="left"
  221. VALIGN="top"
  222. ><A
  223. HREF="function.openssl-pkcs7-decrypt.html"
  224. ACCESSKEY="P"
  225. >Prev</A
  226. ></TD
  227. ><TD
  228. WIDTH="34%"
  229. ALIGN="center"
  230. VALIGN="top"
  231. ><A
  232. HREF="index.html"
  233. ACCESSKEY="H"
  234. >Home</A
  235. ></TD
  236. ><TD
  237. WIDTH="33%"
  238. ALIGN="right"
  239. VALIGN="top"
  240. ><A
  241. HREF="function.openssl-pkcs7-sign.html"
  242. ACCESSKEY="N"
  243. >Next</A
  244. ></TD
  245. ></TR
  246. ><TR
  247. ><TD
  248. WIDTH="33%"
  249. ALIGN="left"
  250. VALIGN="top"
  251. >openssl_pkcs7_decrypt</TD
  252. ><TD
  253. WIDTH="34%"
  254. ALIGN="center"
  255. VALIGN="top"
  256. ><A
  257. HREF="ref.openssl.html"
  258. ACCESSKEY="U"
  259. >Up</A
  260. ></TD
  261. ><TD
  262. WIDTH="33%"
  263. ALIGN="right"
  264. VALIGN="top"
  265. >openssl_pkcs7_sign</TD
  266. ></TR
  267. ></TABLE
  268. ></DIV
  269. ></BODY
  270. ></HTML
  271. >