64) { $key = pack('H*', sha1($key)); } $key = str_pad($key, 64, chr(0x00)); $ipad = str_repeat(chr(0x36), 64); $opad = str_repeat(chr(0x5c), 64); $ipad = $ipad ^ $key; $opad = $opad ^ $key; $hmac = base64_encode(pack('H*', sha1($opad . pack('H*', sha1($ipad . $data))))); // Modify the hmac so it's safe to use in URLs. return strtr($hmac, array('+' => '-', '/' => '_', '=' => '')); } function sha1_hmac_base64($data, $key) { $hmac = base64_encode(hash_hmac('sha1', $data, $key, TRUE)); // Modify the hmac so it's safe to use in URLs. return strtr($hmac, array('+' => '-', '/' => '_', '=' => '')); } $keys[] = "Jefe"; $datas[] = "what do ya want for nothing?"; $keys[] = str_repeat(chr(0xaa), 80); $datas[] = "Test Using Larger Than Block-Size Key - Hash Key First"; $keys[] = str_repeat(chr(0xaa), 80); $datas[] = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"; $keys[] = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"; $datas[] = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"; $keys[] = str_repeat(chr(0x5c), 90); $datas[] = str_repeat(chr(0x5c), 900); foreach ($datas as $i => $data) { if (_imagecache_hmac_base64($data, $keys[$i]) !== sha1_hmac_base64($data, $keys[$i])) { throw new Exception($data); } } echo "success!\n";