Created
November 17, 2012 07:27
-
-
Save udooz/4094024 to your computer and use it in GitHub Desktop.
PowerShell function to generate signed string for WAS Authorization header
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
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