PHP/HMAC SHA1

<?php
function hmac_sha1($key,$data) {
    
$blocksize=64;
    
$hashfunc='sha1';
    if (
strlen($key)>$blocksize)
        
$key=pack('H*'$hashfunc($key));
    
$key=str_pad($key,$blocksize,chr(0x00));
    
$ipad=str_repeat(chr(0x36),$blocksize);
    
$opad=str_repeat(chr(0x5c),$blocksize);
    
$hmac pack(
                
'H*',$hashfunc(
                    (
$key^$opad).pack(
                        
'H*',$hashfunc(
                            (
$key^$ipad).$data
                        
)
                    )
                )
            );
    return 
bin2hex($hmac);
}

$hmac=hmac_sha1('key','The quick brown fox jumps over the lazy dog');
print 
"= ".$hmac;
}
?>

= de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9

이 글에는 0 개의 댓글이 있습니다.