Skip to content

Instantly share code, notes, and snippets.

@udooz
Created November 17, 2012 07:27
Show Gist options
  • Save udooz/4094024 to your computer and use it in GitHub Desktop.
Save udooz/4094024 to your computer and use it in GitHub Desktop.
PowerShell function to generate signed string for WAS Authorization header
function Generate-AuthString
{
param(
[string]$url
,[string]$accountName
,[string]$accountKey
,[string]$requestUtcTime
)
$uri = New-Object System.Uri -ArgumentList $url
$authString = "GET$([char]10)$([char]10)$([char]10)$([char]10)$([char]10)$([char]10)$([char]10)$([char]10)$([char]10)$([char]10)$([char]10)$([char]10)"
$authString += "x-ms-date:" + $requestUtcTime + "$([char]10)"
$authString += "x-ms-version:2011-08-18" + "$([char]10)"
$authString += "/" + $accountName + $uri.AbsolutePath + "$([char]10)"
$authString += "comp:list$([char]10)"
$authString += "include:snapshots,uncommittedblobs,metadata$([char]10)"
$authString += "restype:container$([char]10)"
$authString += "timeout:90"
$dataToMac = [System.Text.Encoding]::UTF8.GetBytes($authString)
$accountKeyBytes = [System.Convert]::FromBase64String($accountKey)
$hmac = new-object System.Security.Cryptography.HMACSHA256((,$accountKeyBytes))
[System.Convert]::ToBase64String($hmac.ComputeHash($dataToMac))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment