Skip to content

Instantly share code, notes, and snippets.

@jaredswarts55
Created May 12, 2015 17:31
Show Gist options
  • Select an option

  • Save jaredswarts55/248ef0e68206a323ab90 to your computer and use it in GitHub Desktop.

Select an option

Save jaredswarts55/248ef0e68206a323ab90 to your computer and use it in GitHub Desktop.
net-newsletter-issue-2 - Powershell Solution
function Get-SHA1($text)
{
$hasher = new-object System.Security.Cryptography.SHA256Managed
$toHash = [System.Text.Encoding]::UTF8.GetBytes($text)
$hashByteArray = $hasher.ComputeHash($toHash)
foreach($byte in $hashByteArray)
{
$res += $byte.ToString("x2")
}
return $res;
}
$pairs = (gc .\challenge.json |
out-string |
ConvertFrom-Json).psobject.properties |
sort-object Name |
% { "$($_.Name)=$([Web.HttpUtility]::UrlEncode($_.Value) -replace "\+","%20")"}
$unixEpoch = (New-TimeSpan -Start (Get-Date -date "1/1/1970") -End (Get-Date "5/12/2015")).TotalMilliseconds
write-host $unixEpoch
$query=[string]::Join('&', $pairs) + "&timestamp=$unixEpoch"
$toHash = ($query + "1234MySuperSecretKey4321")
$hash = Get-SHA1($toHash)
write-host "$query&signature=$hash"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment