Created
May 25, 2021 10:40
-
-
Save yippeykeiyay/73543f941fee9b7692b4d58dab5f184d to your computer and use it in GitHub Desktop.
PowerShell public & private key hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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