System API > Authentication

Authentication

Authentication is achieved using a signature generated using your public key and current UTC Unix timestamp, signed using SHA1 encryption with your private key.

The URI should then contain the plain text public key, the time used in the signature and the signature itself (along with any other desired URI parameters specific to the end-point being communicated with).

Providing your subscription plan has the correct access rights, you can generate your API keys through the portal. Just click on the avatar in the top right corner, click on 'Settings' then 'API Keys' from the left menu.

Request Parameters

Name Description Example Required
public_key Your public key rapidspike-aabC2sA1 yes
time UTC Unix timestamp 1494001089 yes
signature The SHA1 signature dc707aff66175a51d1698f2ee01d94d8e10b051d yes

PHP Signing Example

// Set timezone to UTC
date_default_timezone_set('UTC');

// Provided public and private keys
$publicKey = 'xxxxxxxxxxx';
$privateKey = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy';

// 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;

Powershell Script Signing Example

Thanks to Khuong Phan - duykhuongkid@gmail.com - for providing this example.

# Provided public and private keys
$publicKey = 'xxxxxxxxxxx';
$privateKey = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy';

# Unix timestamp
$unixTime=[int][double]::Parse($(Get-Date -date (Get-Date).ToUniversalTime()-uformat %s))

# Capture the time and package with public key
$package = "$($publicKey)`n$($unixTime)"

# SHA1 hash using the private key and then URL encode the signature
$hmacsha = [System.Security.Cryptography.KeyedHashAlgorithm]::Create("HMACSHA1")
$hmacsha.key = [Text.Encoding]::ASCII.GetBytes($privateKey)

$signature = $hmacsha.ComputeHash([Text.Encoding]::ASCII.GetBytes($package))
$signature = [System.Net.WebUtility]::UrlEncode([Convert]::ToBase64String($signature))

# Create request Url
$requestUri = "?public_key=" + $publicKey + "&time=" + $unixTime + "&signature=" + $signature;
$requestUrl = "https://api.rapidspike.com/v1/assets" + $requestUri;