1
0
mirror of https://github.com/php/doc-ru.git synced 2026-03-27 01:02:19 +01:00
Files
archived-doc-ru/reference/mcrypt/examples.xml
2021-01-05 20:16:26 +03:00

71 lines
2.6 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: be2383c6f9525dfc90b95764c7320edb501b7091 Maintainer: rjhdby Status: ready -->
<!-- Reviewed: yes Maintainer: sergey -->
<appendix xml:id="mcrypt.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
&reftitle.examples;
<para>
Mcrypt можно использовать для шифрования и
дешифрования с использованием вышеупомянутых
шифров. Если модуль собран с
<literal>libmcrypt-2.2.x</literal>, четыре важных
команды mcrypt (<function>mcrypt_cfb</function>,
<function>mcrypt_cbc</function>, <function>mcrypt_ecb</function>
и <function>mcrypt_ofb</function>) могут работать в
обоих режимах, именуемых
<constant>MCRYPT_ENCRYPT</constant> и
<constant>MCRYPT_DECRYPT</constant> соответственно.
</para>
<para>
Если модуль собран с libmcrypt 2.4.x или 2.5.x,
эти функции также будут доступны, но рекомендуется
использовать более продвинутые функции.
<example>
<title>Шифрование с помощью <literal>AES</literal> с
256-битным ключом для версии 2.4.x и выше в режиме
<literal>CBC</literal></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>
Этот пример вернёт зашифрованные данные в строке
<literal>$encrypted_data</literal>. Более полные
примеры смотрите в описании функции
<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
-->