php-doc-en/reference/mcrypt/examples.xml
Hannes Magnusson 1b05071ab0 MFB: Upgrade to the new-reference-structure
- (Created missing setup sections in setup.xml, if any)
 - Moved the intro to book.xml
 - Changed the intro ID from <extname>.intro to intro.<extname>
 - Moved the constants entity to book.xml
 - Changed constants.xml to be an appendix
 - Moved the mcrypt.ciphers section into its own chapter (ciphers.xml)
 - Moved the mcrypt.examples section into its own chapter (examples.xml)
 - Moved the requirements and resources sections to setup.xml
 - Moved the configure and ini entities to setup.xml


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@248996 c90b9560-bf6c-de11-be94-00142212c4b1
2007-12-26 13:23:26 +00:00

75 lines
2.4 KiB
XML

<?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
-->