<div dir="ltr">Other PHP function:<div><br></div><div><div><?php</div><div>function hmac_sha1($data, $key, $raw_output=FALSE) {</div><div><span class="" style="white-space:pre"> </span>$block_size = 64; // SHA-1 block size</div>
<div><br></div><div><span class="" style="white-space:pre"> </span>if (strlen($key) > $block_size) {</div><div><span class="" style="white-space:pre"> </span>$k = pack("H*", sha1($key));</div><div><span class="" style="white-space:pre"> </span>} else {</div>
<div><span class="" style="white-space:pre"> </span>$k = str_pad($key, $block_Size, "\x00", STR_PAD_RIGHT);</div><div><span class="" style="white-space:pre"> </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>$ki = '';</div>
<div><span class="" style="white-space:pre"> </span>for($i = 0; $i < $block_size; $i++) {</div><div><span class="" style="white-space:pre"> </span>$ki .= chr(ord(substr($k, $i, 1)) ^ 0x36);</div><div><span class="" style="white-space:pre"> </span>}</div>
<div><span class="" style="white-space:pre"> </span>$ko = '';</div><div><span class="" style="white-space:pre"> </span>for($i = 0; $i < $block_size; $i++) {</div><div><span class="" style="white-space:pre"> </span>$ko .= chr(ord(substr($k, $i, 1)) ^ 0x5C);</div>
<div><span class="" style="white-space:pre"> </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>$h = sha1($ko . pack('H*', sha1($ki . $data)));</div><div><span class="" style="white-space:pre"> </span>if ($raw_output) {</div>
<div><span class="" style="white-space:pre"> </span>return pack('H*', $h);</div><div><span class="" style="white-space:pre"> </span>} else {</div><div><span class="" style="white-space:pre"> </span>return $h;</div>
<div><span class="" style="white-space:pre"> </span>}</div><div>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>echo hmac_sha1("The quick brown fox jumped over the lazy dog.", "secret");</div>
<div>?></div><div><br></div><div style>Result:</div><div style><br></div><div style><span style="color:rgb(0,0,0);font-family:'Times New Roman';font-size:medium">5d4db2701c7b07de0e23db3e4f22e88bc1a31a49</span><br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/3/23 silvioprog <span dir="ltr"><<a href="mailto:silvioprog@gmail.com" target="_blank">silvioprog@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div>Hello,</div><div><br></div>I could be wrong, but I think that Synapse function have a bug. See:<div><br></div><div>Using PHP:</div><div><div><?php<br></div><div><div><span style="white-space:pre-wrap"> </span>echo hash_hmac("ripemd160", "The quick brown fox jumped over the lazy dog.", "secret");</div>
<div>?></div><div>Result:<br></div><div class="gmail_extra"><div>b8e7ae12510bdfb1812e463a7f086122cf37e4f7<br></div><div><br></div><div>Using the <a href="http://www.freeformatter.com" target="_blank">http://www.freeformatter.com</a> site<br>
</div><div>Result:<br></div><div>5d4db2701c7b07de0e23db3e4f22e88bc1a31a49<br></div><div><br></div><div>Using Synapse:</div><div><div>uses</div><div> synacode;</div><div>begin<br></div><div> Write(HMAC_SHA1('The quick brown fox jumped over the lazy dog.', 'secret');</div>
<div>end.</div></div><div>Result:<br></div><div>]M?p { ? #?>O"?c I</div></div></div></div></div></blockquote></div><div><br></div>-- <br>Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a>
</div></div></div>