<?xml version="1.0" encoding="utf-8"?> <!-- $Revision$ --> <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 <literal>libmcrypt-2.2.x</literal>, 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 <constant>MCRYPT_ENCRYPT</constant> and <constant>MCRYPT_DECRYPT</constant>, respectively. </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 <literal>AES</literal> with a 256-bit key under 2.4.x and higher in <literal>CBC</literal> mode</title> <programlisting role="php"> <![CDATA[ <?php $key = hash('sha256', 'this is a secret key', true); $input = "Let us meet at 9 o'clock at the secret place."; $td = mcrypt_module_open('rijndael-128', '', 'cbc', ''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_URANDOM); 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:"~/.phpdoc/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 -->