Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This PowerShell script is part of video https://www.youtube.com/watch?v=BI7F4-4zfEY
- #---------------------------------------------------------------------
- # Date : 28-09-2017
- # Script name : Generate_SAS_token.ps1
- # Description : This script will generate a SAS token from the
- # Service Bus queue primary key.
- #
- # Created by : Basic Cloud
- # Extra module :
- # Copyright : ©2017 Basic Cloud, all rights reserved.
- # History : Basic Cloud 20170928 Initial version
- #---------------------------------------------------------------------
- [Reflection.Assembly]::LoadWithPartialName("System.Web")| out-null
- # Enter the information about the Service Bus
- $URI="basiccloud.servicebus.windows.net/basiccloud/messages/head"
- $Access_Policy_Name="RootManageSharedAccessKey"
- $Access_Policy_Key="rd1sFC/Q1mySrpa8ygiJpyhd3wO5Q7yN5V0FycR0diU="
- # Set the token expiration
- $Expires=([DateTimeOffset]::Now.ToUnixTimeSeconds())+300
- # Build the token
- $SignatureString=[System.Web.HttpUtility]::UrlEncode($URI)+ "`n" + [string]$Expires
- $HMAC = New-Object System.Security.Cryptography.HMACSHA256
- $HMAC.key = [Text.Encoding]::ASCII.GetBytes($Access_Policy_Key)
- $Signature = $HMAC.ComputeHash([Text.Encoding]::ASCII.GetBytes($SignatureString))
- $Signature = [Convert]::ToBase64String($Signature)
- $SASToken = "SharedAccessSignature sr=" + [System.Web.HttpUtility]::UrlEncode($URI) + "&sig=" + [System.Web.HttpUtility]::UrlEncode($Signature) + "&se=" + $Expires + "&skn=" + $Access_Policy_Name
- # Output the value
- $SASToken
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement