<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.mcrypt.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.mcrypt-module-open.php',
    1 => 'mcrypt_module_open',
    2 => 'Opens the module of the algorithm and the mode to be used',
  ),
  'up' => 
  array (
    0 => 'ref.mcrypt.php',
    1 => 'Mcrypt Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.mcrypt-module-is-block-mode.php',
    1 => 'mcrypt_module_is_block_mode',
  ),
  'next' => 
  array (
    0 => 'function.mcrypt-module-self-test.php',
    1 => 'mcrypt_module_self_test',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/mcrypt/functions/mcrypt-module-open.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.mcrypt-module-open" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mcrypt_module_open</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.2, PHP 5, PHP 7 &lt; 7.2.0, PECL mcrypt &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">mcrypt_module_open</span> &mdash; <span class="dc-title">Opens the module of the algorithm and the mode to be used</span></p>

 </div>
 <div id="function.mcrypt-module-open-refsynopsisdiv">
  <div class="warning"><strong class="warning">Avviso</strong><p class="simpara">This function has been
<em>DEPRECATED</em> as of PHP 7.1.0 and
<em>REMOVED</em> as of PHP 7.2.0. Relying on this function
is highly discouraged.</p></div>
 </div>
 <div class="refsect1 description" id="refsect1-function.mcrypt-module-open-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mcrypt_module_open</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$algorithm</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$algorithm_directory</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$mode</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$mode_directory</code></span><br>): <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span></div>

  <p class="simpara">
   This function opens the module of the algorithm and the mode to be used.
   The name of the algorithm is specified in algorithm, e.g. <code class="literal">&quot;twofish&quot;</code> or is
   one of the <strong><code>MCRYPT_ciphername</code></strong> constants.  The module is closed by calling
   <span class="function"><a href="function.mcrypt-module-close.php" class="function">mcrypt_module_close()</a></span>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mcrypt-module-open-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <dl>
   
    <dt><code class="parameter">algorithm</code></dt>
    <dd>
     <p class="para">Una tra le costanti <strong><code>MCRYPT_ciphername</code></strong>, oppure il nome dell&#039;algoritmo sotto forma di stringa.</p>
    </dd>
   
   
    <dt><code class="parameter">algorithm_directory</code></dt>
    <dd>
     <span class="simpara">
      The <code class="parameter">algorithm_directory</code> parameter is used to locate
      the encryption module. When you supply a directory name, it is used.  When
      you set it to an empty string (<code class="literal">&quot;&quot;</code>), the value set by the
      <code class="literal">mcrypt.algorithms_dir</code> <var class="filename">php.ini</var> directive is used. When
      it is not set, the default directory that is used is the one that was compiled
      into libmcrypt (usually <var class="filename">/usr/local/lib/libmcrypt</var>).
     </span>
    </dd>
   
   
    <dt><code class="parameter">mode</code></dt>
    <dd>
     <p class="para">Una tra le costanti <strong><code>MCRYPT_MODE_modename</code></strong>, oppure una tra le seguenti stringhe: &quot;ecb&quot;, &quot;cbc&quot;, &quot;cfb&quot;, &quot;ofb&quot;, &quot;nofb&quot; o &quot;stream&quot;.</p>
    </dd>
   
   
    <dt><code class="parameter">mode_directory</code></dt>
    <dd>
     <span class="simpara">
      The <code class="parameter">mode_directory</code> parameter is used to locate
      the encryption module. When you supply a directory name, it is used.  When
      you set it to an empty string (<code class="literal">&quot;&quot;</code>), the value set by the
      <code class="literal">mcrypt.modes_dir</code> <var class="filename">php.ini</var> directive is used. When
      it is not set, the default directory that is used is the one that was compiled-in
      into libmcrypt (usually <var class="filename">/usr/local/lib/libmcrypt</var>).
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mcrypt-module-open-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="simpara">
   Normally it returns an encryption descriptor, or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on error.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mcrypt-module-open-examples">
  <h3 class="title">Esempi</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="function"><strong>mcrypt_module_open()</strong></span> Examples</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />    $td </span><span style="color: #007700">= </span><span style="color: #0000BB">mcrypt_module_open</span><span style="color: #007700">(</span><span style="color: #0000BB">MCRYPT_DES</span><span style="color: #007700">, </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />        </span><span style="color: #0000BB">MCRYPT_MODE_ECB</span><span style="color: #007700">, </span><span style="color: #DD0000">'/usr/lib/mcrypt-modes'</span><span style="color: #007700">);<br /><br />    </span><span style="color: #0000BB">$td </span><span style="color: #007700">= </span><span style="color: #0000BB">mcrypt_module_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'rijndael-256'</span><span style="color: #007700">, </span><span style="color: #DD0000">''</span><span style="color: #007700">, </span><span style="color: #DD0000">'ofb'</span><span style="color: #007700">, </span><span style="color: #DD0000">''</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
  <p class="simpara">
   The first line in the example above will try to open the <code class="literal">DES</code> cipher from
   the default directory and the <code class="literal">ECB</code> mode from the directory
   <var class="filename">/usr/lib/mcrypt-modes</var>. The second example uses
   strings as name for the cipher and mode, this only works when the
   extension is linked against libmcrypt 2.4.x or 2.5.x.
  </p>

  <div class="example" id="example-2">
   <p><strong>Example #2 Using <span class="function"><strong>mcrypt_module_open()</strong></span> in encryption</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />    </span><span style="color: #FF8000">/* Open the cipher */<br />    </span><span style="color: #0000BB">$td </span><span style="color: #007700">= </span><span style="color: #0000BB">mcrypt_module_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'rijndael-256'</span><span style="color: #007700">, </span><span style="color: #DD0000">''</span><span style="color: #007700">, </span><span style="color: #DD0000">'ofb'</span><span style="color: #007700">, </span><span style="color: #DD0000">''</span><span style="color: #007700">);<br /><br />    </span><span style="color: #FF8000">/* Create the IV and determine the keysize length, use MCRYPT_RAND<br />     * on Windows instead */<br />    </span><span style="color: #0000BB">$iv </span><span style="color: #007700">= </span><span style="color: #0000BB">mcrypt_create_iv</span><span style="color: #007700">(</span><span style="color: #0000BB">mcrypt_enc_get_iv_size</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</span><span style="color: #007700">), </span><span style="color: #0000BB">MCRYPT_DEV_RANDOM</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">$ks </span><span style="color: #007700">= </span><span style="color: #0000BB">mcrypt_enc_get_key_size</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</span><span style="color: #007700">);<br /><br />    </span><span style="color: #FF8000">/* Create key (example only: MD5 is not a good hash algorithm for this) */<br />    </span><span style="color: #0000BB">$key </span><span style="color: #007700">= </span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">hash</span><span style="color: #007700">(</span><span style="color: #DD0000">'md5'</span><span style="color: #007700">, </span><span style="color: #DD0000">'very secret key'</span><span style="color: #007700">), </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">$ks</span><span style="color: #007700">);<br /><br />    </span><span style="color: #FF8000">/* Intialize encryption */<br />    </span><span style="color: #0000BB">mcrypt_generic_init</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</span><span style="color: #007700">, </span><span style="color: #0000BB">$key</span><span style="color: #007700">, </span><span style="color: #0000BB">$iv</span><span style="color: #007700">);<br /><br />    </span><span style="color: #FF8000">/* Encrypt data */<br />    </span><span style="color: #0000BB">$encrypted </span><span style="color: #007700">= </span><span style="color: #0000BB">mcrypt_generic</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</span><span style="color: #007700">, </span><span style="color: #DD0000">'This is very important data'</span><span style="color: #007700">);<br /><br />    </span><span style="color: #FF8000">/* Terminate encryption handler */<br />    </span><span style="color: #0000BB">mcrypt_generic_deinit</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</span><span style="color: #007700">);<br /><br />    </span><span style="color: #FF8000">/* Initialize encryption module for decryption */<br />    </span><span style="color: #0000BB">mcrypt_generic_init</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</span><span style="color: #007700">, </span><span style="color: #0000BB">$key</span><span style="color: #007700">, </span><span style="color: #0000BB">$iv</span><span style="color: #007700">);<br /><br />    </span><span style="color: #FF8000">/* Decrypt encrypted string */<br />    </span><span style="color: #0000BB">$decrypted </span><span style="color: #007700">= </span><span style="color: #0000BB">mdecrypt_generic</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</span><span style="color: #007700">, </span><span style="color: #0000BB">$encrypted</span><span style="color: #007700">);<br /><br />    </span><span style="color: #FF8000">/* Terminate decryption handle and close module */<br />    </span><span style="color: #0000BB">mcrypt_generic_deinit</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">mcrypt_module_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$td</span><span style="color: #007700">);<br /><br />    </span><span style="color: #FF8000">/* Show string */<br />    </span><span style="color: #007700">echo </span><span style="color: #0000BB">trim</span><span style="color: #007700">(</span><span style="color: #0000BB">$decrypted</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mcrypt-module-open-seealso">
  <h3 class="title">Vedere anche:</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.mcrypt-module-close.php" class="function" rel="rdfs-seeAlso">mcrypt_module_close()</a> - Closes the mcrypt module</span></li>
   <li><span class="function"><a href="function.mcrypt-generic.php" class="function" rel="rdfs-seeAlso">mcrypt_generic()</a> - This function encrypts data</span></li>
   <li><span class="function"><a href="function.mdecrypt-generic.php" class="function" rel="rdfs-seeAlso">mdecrypt_generic()</a> - Decrypts data</span></li>
   <li><span class="function"><a href="function.mcrypt-generic-init.php" class="function" rel="rdfs-seeAlso">mcrypt_generic_init()</a> - This function initializes all buffers needed for encryption</span></li>
   <li><span class="function"><a href="function.mcrypt-generic-deinit.php" class="function" rel="rdfs-seeAlso">mcrypt_generic_deinit()</a> - This function deinitializes an encryption module</span></li>
  </ul>
 </div>

</div><?php manual_footer($setup); ?>