<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>This function initializes all buffers needed for encryption</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.mcrypt-generic-end.html">mcrypt_generic_end</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.mcrypt-generic.html">mcrypt_generic</a></div> <div class="up"><a href="ref.mcrypt.html">Mcrypt Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.mcrypt-generic-init" class="refentry"> <div class="refnamediv"> <h1 class="refname">mcrypt_generic_init</h1> <p class="verinfo">(PHP 4 >= 4.0.2, PHP 5)</p><p class="refpurpose"><span class="refname">mcrypt_generic_init</span> — <span class="dc-title">This function initializes all buffers needed for encryption</span></p> </div> <div class="refsect1 description" id="refsect1-function.mcrypt-generic-init-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><strong>mcrypt_generic_init</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$td</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$key</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$iv</code></span> )</div> <p class="para rdfs-comment"> You need to call this function before every call to <span class="function"><a href="function.mcrypt-generic.html" class="function">mcrypt_generic()</a></span> or <span class="function"><a href="function.mdecrypt-generic.html" class="function">mdecrypt_generic()</a></span>. </p> </div> <div class="refsect1 parameters" id="refsect1-function.mcrypt-generic-init-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">td</code></em></span> <dd> <p class="para"> The encryption descriptor. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">key</code></em></span> <dd> <p class="para"> The maximum length of the key should be the one obtained by calling <span class="function"><a href="function.mcrypt-enc-get-key-size.html" class="function">mcrypt_enc_get_key_size()</a></span> and every value smaller than this is legal. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">iv</code></em></span> <dd> <p class="para"> The IV should normally have the size of the algorithms block size, but you must obtain the size by calling <span class="function"><a href="function.mcrypt-enc-get-iv-size.html" class="function">mcrypt_enc_get_iv_size()</a></span>. IV is ignored in ECB. IV MUST exist in CFB, CBC, STREAM, nOFB and OFB modes. It needs to be random and unique (but not secret). The same IV must be used for encryption/decryption. If you do not want to use it you should set it to zeros, but this is not recommended. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.mcrypt-generic-init-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The function returns a negative value on error: -3 when the key length was incorrect, -4 when there was a memory allocation problem and any other return value is an unknown error. If an error occurs a warning will be displayed accordingly. <strong><code>FALSE</code></strong> is returned if incorrect parameters were passed. </p> </div> <div class="refsect1 seealso" id="refsect1-function.mcrypt-generic-init-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.mcrypt-module-open.html" class="function" rel="rdfs-seeAlso">mcrypt_module_open()</a> - Opens the module of the algorithm and the mode to be used</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.mcrypt-generic-end.html">mcrypt_generic_end</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.mcrypt-generic.html">mcrypt_generic</a></div> <div class="up"><a href="ref.mcrypt.html">Mcrypt Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>