downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/function.hash-hmac.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/ref.hash.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'function.hash-hmac.php',
   
1 => 'hash_hmac',
  ),
 
'up' =>
  array (
   
0 => 'ref.hash.php',
   
1 => 'Hash Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.hash-hmac-file.php',
   
1 => 'hash_hmac_file',
  ),
 
'next' =>
  array (
   
0 => 'function.hash-init.php',
   
1 => 'hash_init',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="function.hash-hmac" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">hash_hmac</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.2, PECL hash &gt;= 1.1)</p><p class="refpurpose"><span class="refname">hash_hmac</span> &mdash; <span class="dc-title">Generate a keyed hash value using the HMAC method</span></p>

 </div>
 <a name="function.hash-hmac.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><b>hash_hmac</b></span>
    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$algo</tt></span>
   , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$data</tt></span>
   , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$key</tt></span>
   [, <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$raw_output</tt><span class="initializer"> = false</span></span>
  ] )</div>


 </div>

 <a name="function.hash-hmac.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">algo</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       Name of selected hashing algorithm (i.e. &quot;md5&quot;, &quot;sha256&quot;, &quot;haval160,4&quot;, etc..)
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">data</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       Message to be hashed.
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">key</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       Shared secret key used for generating the HMAC variant of the message digest.
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">raw_output</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       When set to <b><tt class="constant">TRUE</tt></b>, outputs raw binary data.
       Default value (<b><tt class="constant">FALSE</tt></b>) outputs lowercase hexits.
      </p>
     </dd>

   
   </dl>
<p>
  </p>
 </div>


 <a name="function.hash-hmac.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns a string containing the calculated message digest as lowercase hexits
   unless <i><tt class="parameter">raw_output</tt></i>
 is set to true in which case the raw
   binary representation of the message digest is returned.
  </p>
 </div>


 <a name="function.hash-hmac.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 <b>hash_hmac()</b> example</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">hash_hmac</span><span style="color: #007700">(</span><span style="color: #DD0000">'ripemd160'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'The&nbsp;quick&nbsp;brown&nbsp;fox&nbsp;jumped&nbsp;over&nbsp;the&nbsp;lazy&nbsp;dog.'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'secret'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents para"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
b8e7ae12510bdfb1812e463a7f086122cf37e4f7
</pre></div>
    </div>
   </div><p>
  </p>
 </div>


 <a name="function.hash-hmac.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="function.hash.php" class="function" rel="rdfs-seeAlso">hash()</a> - Generate a hash value (message digest)</li>
    <li class="member"><a href="function.hash-init.php" class="function" rel="rdfs-seeAlso">hash_init()</a> - Initialize an incremental hashing context</li>
    <li class="member"><a href="function.hash-hmac-file.php" class="function" rel="rdfs-seeAlso">hash_hmac_file()</a> - Generate a keyed hash value using the HMAC method and the contents of a given file</li>
   </ul><p>
  </p>
 </div>


</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites