[fpc-pascal] HMAC_SHA1 and FPC
silvioprog
silvioprog at gmail.com
Sat Mar 23 18:26:51 CET 2013
Other PHP function:
<?php
function hmac_sha1($data, $key, $raw_output=FALSE) {
$block_size = 64; // SHA-1 block size
if (strlen($key) > $block_size) {
$k = pack("H*", sha1($key));
} else {
$k = str_pad($key, $block_Size, "\x00", STR_PAD_RIGHT);
}
$ki = '';
for($i = 0; $i < $block_size; $i++) {
$ki .= chr(ord(substr($k, $i, 1)) ^ 0x36);
}
$ko = '';
for($i = 0; $i < $block_size; $i++) {
$ko .= chr(ord(substr($k, $i, 1)) ^ 0x5C);
}
$h = sha1($ko . pack('H*', sha1($ki . $data)));
if ($raw_output) {
return pack('H*', $h);
} else {
return $h;
}
}
echo hmac_sha1("The quick brown fox jumped over the lazy dog.", "secret");
?>
Result:
5d4db2701c7b07de0e23db3e4f22e88bc1a31a49
2013/3/23 silvioprog <silvioprog at gmail.com>
> Hello,
>
> I could be wrong, but I think that Synapse function have a bug. See:
>
> Using PHP:
> <?php
> echo hash_hmac("ripemd160", "The quick brown fox jumped over the lazy
> dog.", "secret");
> ?>
> Result:
> b8e7ae12510bdfb1812e463a7f086122cf37e4f7
>
> Using the http://www.freeformatter.com site
> Result:
> 5d4db2701c7b07de0e23db3e4f22e88bc1a31a49
>
> Using Synapse:
> uses
> synacode;
> begin
> Write(HMAC_SHA1('The quick brown fox jumped over the lazy dog.',
> 'secret');
> end.
> Result:
> ]M?p { ? #?>O"?c I
>
--
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130323/932072c7/attachment.html>
More information about the fpc-pascal
mailing list