Skip to content

Instantly share code, notes, and snippets.

@yippeykeiyay
Last active May 25, 2021 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yippeykeiyay/5644e53595b786e7fbe9ebb029b6fc76 to your computer and use it in GitHub Desktop.
Save yippeykeiyay/5644e53595b786e7fbe9ebb029b6fc76 to your computer and use it in GitHub Desktop.
PHP public & private key hash
<?php
// Set timezone to UTC
date_default_timezone_set('UTC');
// Provided public and private keys
$publicKey = 'put-your-public-key';
$privateKey = 'put-your-private-key-here';
// Capture the time and package with the public key
$time = time();
$package = $publicKey . "\n" . $time;
// SHA1 hash using the private key and then URL encode the signature
$binSignature = hash_hmac('sha1', $package, $privateKey, true);
$uriSignature = urlencode(base64_encode($binSignature));
// Put together the request URI and URL
$requestUri = "?public_key=" . $publicKey . "&time=" . $time . "&signature=" . $uriSignature;
$requestUrl = "https://api.rapidspike.com/v1/assets" . $requestUri;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment