2007-12-26 13:23:26 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2009-07-11 07:57:45 +00:00
|
|
|
<!-- $Revision$ -->
|
2007-12-26 13:23:26 +00:00
|
|
|
|
|
|
|
<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
|
2009-04-19 20:10:23 +00:00
|
|
|
mentioned ciphers. If you linked against <literal>libmcrypt-2.2.x</literal>, the
|
2007-12-26 13:23:26 +00:00
|
|
|
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
|
2009-04-19 20:10:23 +00:00
|
|
|
which are named <constant>MCRYPT_ENCRYPT</constant> and
|
|
|
|
<constant>MCRYPT_DECRYPT</constant>, respectively.
|
2007-12-26 13:23:26 +00:00
|
|
|
<example>
|
2009-04-19 20:10:23 +00:00
|
|
|
<title>Encrypt an input value with <literal>TripleDES</literal>
|
|
|
|
under 2.2.x in <literal>ECB</literal> mode</title>
|
2007-12-26 13:23:26 +00:00
|
|
|
<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>
|
2009-04-19 20:10:23 +00:00
|
|
|
<title>Encrypt an input value with <literal>TripleDES</literal> under 2.4.x and higher in <literal>ECB</literal> mode</title>
|
2007-12-26 13:23:26 +00:00
|
|
|
<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
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2007-12-26 13:23:26 +00:00
|
|
|
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
|
|
|
|
-->
|