Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 1467

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>mcrypt_module_open</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="Mcrypt Encryption Functions"
HREF="ref.mcrypt.html"><LINK
REL="PREVIOUS"
TITLE="mcrypt_module_is_block_mode"
HREF="function.mcrypt-module-is-block-mode.html"><LINK
REL="NEXT"
TITLE="mcrypt_module_self_test"
HREF="function.mcrypt-module-self-test.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.mcrypt-module-is-block-mode.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.mcrypt-module-self-test.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.mcrypt-module-open"
></A
>mcrypt_module_open</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN49540"
></A
><P
>    (PHP 4 &#62;= 4.0.2)</P
>mcrypt_module_open&nbsp;--&nbsp;This function opens the module of the algorithm and the mode to be used</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN49543"
></A
><H2
>Description</H2
>resource <B
CLASS="methodname"
>mcrypt_module_open</B
> ( string algorithm, string algorithm_directory, string mode, string mode_directory)<BR
></BR
><P
>&#13;     This function opens the module of the algorithm and the mode to be used.
     The name of the algorithm is specified in algorithm, eg. "twofish" or is
     one of the MCRYPT_ciphername constants.  The module is closed by calling
     <A
HREF="function.mcrypt-module-close.html"
><B
CLASS="function"
>mcrypt_module_close()</B
></A
>. Normally it returns an
     encryption descriptor, or <TT
CLASS="constant"
><B
>FALSE</B
></TT
> on error.
    </P
><P
>&#13;     The <TT
CLASS="parameter"
><I
>algorithm_directory</I
></TT
> and
     <TT
CLASS="parameter"
><I
>mode_directory</I
></TT
> are used to locate the encryption
     modules. When you supply a directory name, it is used.  When you set one
     of these to the empty string (""), the value set by the
     <TT
CLASS="parameter"
><I
>mcrypt.algorithms_dir</I
></TT
> or
     <TT
CLASS="parameter"
><I
>mcrypt.modes_dir</I
></TT
> ini-directive is used.  When
     these are not set, the default directories that are used are the ones
     that were compiled in into libmcrypt (usally /usr/local/lib/libmcrypt).
    </P
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN49569"
></A
><P
><B
>Example 1. <B
CLASS="function"
>mcrypt_module_open()</B
> Example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
    $td = mcrypt_module_open (MCRYPT_DES, '', MCRYPT_MODE_ECB, '/usr/lib/mcrypt-modes');
    $td = mcrypt_module_open ('rijndael-256', '', 'ofb', '');
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     The first line in the example above will try to open the DES cipher from
     the default directory and the EBC mode from the directory
     <TT
CLASS="filename"
>/usr/lib/mcrypt-modes</TT
>. The second example uses
     strings as name for the cipher an dmode, this only works when the
     extension is linked against libmcrypt 2.4.x or 2.5.x.
    </P
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN49576"
></A
><P
><B
>Example 2. Using <B
CLASS="function"
>mcrypt_module_open()</B
> in encryption</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
    /* Open the cipher */
    $td = mcrypt_module_open ('rijndael-256', '', 'ofb', '');

    /* Create the IV and determine the keysize length */
    $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
    $ks = mcrypt_enc_get_key_size ($td);

    /* Create key */
    $key = substr (md5 ('very secret key'), 0, $ks);

    /* Intialize encryption */
    mcrypt_generic_init ($td, $key, $iv);

    /* Encrypt data */
    $encrypted = mcrypt_generic ($td, 'This is very important data');

    /* Terminate encryption handler */
    mcrypt_generic_deinit ($td);

    /* Initialize encryption module for decryption */
    mcrypt_generic_init ($td, $key, $iv);

    /* Decrypt encrypted string */
    $decrypted = mdecrypt_generic ($td, $encrypted);

    /* Terminate decryption handle and close module */
    mcrypt_generic_deinit ($td);
    mcrypt_module_close ($td);

    /* Show string */
    echo trim ($decrypted)."\n";
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     The first line in the example above will try to open the DES cipher from
     the default directory and the EBC mode from the directory
     <TT
CLASS="filename"
>/usr/lib/mcrypt-modes</TT
>. The second example uses
     strings as name for the cipher an dmode, this only works when the
     extension is linked against libmcrypt 2.4.x or 2.5.x.
    </P
><P
>&#13;     See also <A
HREF="function.mcrypt-module-close.html"
><B
CLASS="function"
>mcrypt_module_close()</B
></A
>,
     <A
HREF="function.mcrypt-generic.html"
><B
CLASS="function"
>mcrypt_generic()</B
></A
>,
     <A
HREF="function.mdecrypt-generic.html"
><B
CLASS="function"
>mdecrypt_generic()</B
></A
>,
     <A
HREF="function.mcrypt-generic-init.html"
><B
CLASS="function"
>mcrypt_generic_init()</B
></A
> and
     <A
HREF="function.mcrypt-generic-deinit.html"
><B
CLASS="function"
>mcrypt_generic_deinit()</B
></A
>.
    </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.mcrypt-module-is-block-mode.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.mcrypt-module-self-test.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>mcrypt_module_is_block_mode</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.mcrypt.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>mcrypt_module_self_test</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>