Complexity Simplified

Amazon AWIS - Alexa System in VB.NET (2015)

Here is a code snipped for the VB version of the Alexa (AWIS) system for those who would like it, If you would like the full source let me know

Dim awsAccessId As String = "amazon--id--abcde"

Dim awsSecretKey As String = "abcde---secretkey---abcde"

Dim alexaUrl As String =

Dim queryStringList As New Dictionary(Of String, String)()

Dim timeStamp As String = System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", System.Globalization.CultureInfo.InvariantCulture)

queryStringList.Add("Url", URL.Text)

queryStringList.Add("Action", "UrlInfo")

queryStringList.Add("Count", "10")

queryStringList.Add("ResponseGroup", "Rank,ContactInfo,Categories,UsageStats,Keywords,SiteData,LinksInCount")

queryStringList.Add("SignatureMethod", "HmacSHA256")

queryStringList.Add("SignatureVersion", "2")

queryStringList.Add("Start", "1")

queryStringList.Add("Timestamp", timeStamp)

queryStringList = queryStringList.OrderBy(Function(x) x.Key).ToDictionary(Function(x) x.Key, Function(x) x.Value)

Dim queryString As String = ""

queryString = "AWSAccessKeyId=" + UpperCaseUrlEncode(awsAccessId) + "&"

'url encode query string values

For Each item In queryStringList

queryString += item.Key + "=" + UpperCaseUrlEncode(item.Value) + "&"


'remove trailing &

queryString = queryString.TrimEnd(New Char() {"&"c})

alexaUrl += queryString

'must create signature

Dim stringToEncode As String = Convert.ToString("GET" & vbLf & "" & vbLf & "/" & vbLf) & queryString

Dim provider As New System.Security.Cryptography.HMACSHA256(System.Text.Encoding.UTF8.GetBytes(awsSecretKey))

Dim tmpSource As Byte()

Dim tmpHash As Byte()

'Create a byte array from source data.

tmpSource = System.Text.Encoding.UTF8.GetBytes(stringToEncode)

'Compute hash based on source data.

tmpHash = provider.ComputeHash(tmpSource)

'Convert hash to string

Dim endcodeQueryString As String = Convert.ToBase64String(tmpHash, 0, tmpHash.Length)

'alexaUrl += "&Signature=" + server.UrlEncode(endcodeQueryString)

alexaUrl += "&Signature=" + endcodeQueryString