File: examples.xml

package info (click to toggle)
php-doc 20081024-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 57,752 kB
  • ctags: 3,858
  • sloc: xml: 686,554; php: 19,446; perl: 610; cpp: 500; makefile: 336; sh: 114; awk: 28
file content (75 lines) | stat: -rw-r--r-- 2,431 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.2 $ -->

<appendix xml:id="mcrypt.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
 &reftitle.examples;
 <para>
  Mcrypt can be used to encrypt and decrypt using the above
  mentioned ciphers. If you linked against libmcrypt-2.2.x, the
  four important mcrypt commands (<function>mcrypt_cfb</function>,
  <function>mcrypt_cbc</function>, <function>mcrypt_ecb</function>,
  and <function>mcrypt_ofb</function>) can operate in both modes
  which are named MCRYPT_ENCRYPT and MCRYPT_DECRYPT, respectively.
  <example>
   <title>Encrypt an input value with TripleDES under 2.2.x in ECB mode</title>
   <programlisting role="php">
<![CDATA[
<?php
$key = "this is a secret key";
$input = "Let us meet at 9 o'clock at the secret place.";

$encrypted_data = mcrypt_ecb (MCRYPT_3DES, $key, $input, MCRYPT_ENCRYPT);
?>
]]>
   </programlisting>
  </example>
  This example will give you the encrypted data as a string in
  <literal>$encrypted_data</literal>.
 </para>
 <para>
  If you linked against libmcrypt 2.4.x or 2.5.x, these functions are still
  available, but it is recommended that you use the advanced functions.
  <example>
   <title>Encrypt an input value with TripleDES under 2.4.x and higher in ECB mode</title>
   <programlisting role="php">
<![CDATA[
<?php
    $key = "this is a secret key";
    $input = "Let us meet at 9 o'clock at the secret place.";

    $td = mcrypt_module_open('tripledes', '', 'ecb', '');
    $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
    mcrypt_generic_init($td, $key, $iv);
    $encrypted_data = mcrypt_generic($td, $input);
    mcrypt_generic_deinit($td);
    mcrypt_module_close($td);
?>
]]>
   </programlisting>
  </example>
  This example will give you the encrypted data as a string in
  <literal>$encrypted_data</literal>.  For a full example see
  <function>mcrypt_module_open</function>.
 </para>
</appendix>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->