Debug> ' . $msg; } echo "\n"; } if ($exit) { die('

Exit

'); } } function genRandRaw($len) { $h = hash_hmac('sha1', rand(9999,9999999), 'dj*ccbcuiiurubrvnubcdluul', true); $a = str_split($h); //print_r($a); $a = array_slice($a, 0, $len); //print_r($a); $s = implode($a); //outputToFile('out', $s); return $s; } // Return eg. 2008-11-21T06:11:55 // function getUTCTimeStamp() { date_default_timezone_set('UTC'); return date('Y-m-d\TH:i:s', time()); } // Sign a http query string in the array of key-value pairs // return b64 encoded hmac hash function sign($a, $apiKey, $debug=false) { ksort($a); $qs = ''; $n = count($a); $i = 0; foreach (array_keys($a) as $key) { $qs .= trim($key).'='.trim($a[$key]); if (++$i < $n) { $qs .= '&'; } } // Generate the signature //debug('API key: '.$apiKey); // API key of the client debug('SIGN: '.$qs); // the TRUE at the end states we want the raw value, not hexadecimal form $hmac = hash_hmac('sha1', utf8_encode($qs), $apiKey, true); $hmac = base64_encode($hmac); if ($debug) { debug('h='.$hmac); } return $hmac; } // sign an array of query string function outputToFile($outFname, $content, $mode, $append = false) { $out = fopen($outFname, ($append ? "a" : "w")); fwrite($out, $content); fclose($out); } ?>