64) { $key = sha1($key); $key_length = 40; } //pad secret with 0x0 to get a 64 byte secret? if ($key_lenght < 64) { $secret = $key.str_repeat(chr(0), (64 - $key_lenght)); } else { //64 bytes long, we can use the key directly $secret = $key; } //hash and return it return base64_encode(sha1(//create the string we have to hash ($secret^str_repeat(chr(0x5c), 64)). //pad the key for inner digest //subhash sha1(//create substring we have to hash ($secret^str_repeat(chr(0x36), 64)). //pad the key for outer digest $str, //we need RAW output! true), //we need RAW output! true)); } //example echo hmac_sha1("this is the data to hash", "my secret key, ASCII only for best compatibility"); ?>