Skip to content

Instantly share code, notes, and snippets.

@yippeykeiyay
Created May 25, 2021 10:40
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/73543f941fee9b7692b4d58dab5f184d to your computer and use it in GitHub Desktop.
Save yippeykeiyay/73543f941fee9b7692b4d58dab5f184d to your computer and use it in GitHub Desktop.
PowerShell public & private key hash
# 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment