I have been searching all across the internet and in addition also liaising with the servidedesk people from Google on this subject. With no luck so far.
I am trying to use the Google API for Directions via a web service call in VBA. My code works really good and it gives the correct results from the webservice. However they require that I encrypt the data before sending it to them if i want to send more than a few thousand daily requests.
They have a code on the following side but not related to VBA and only for VB.net.
Is anyone in here familiar with this codes usability in VBA? does VBA have the required libraries to use with some minor adjustments to the code or?
Option Explicit On
Option Strict On
Imports System
Imports System.Security.Cryptography
Imports System.Text
Namespace SignUrl
Public Module GoogleUrlSigner
Public Function Sign(ByVal url As String, ByVal keyString As String) As String
Dim encoding As ASCIIEncoding = New ASCIIEncoding()
'URL-safe decoding
Dim privateKeyBytes As Byte() = Convert.FromBase64String(keyString.Replace("-", "+").Replace("_", "/"))
Dim objURI As Uri = New Uri(url)
Dim encodedPathAndQueryBytes As Byte() = encoding.GetBytes(objURI.LocalPath & objURI.Query)
'compute the hash
Dim algorithm As HMACSHA1 = New HMACSHA1(privateKeyBytes)
Dim hash As Byte() = algorithm.ComputeHash(encodedPathAndQueryBytes)
'convert the bytes to string and make url-safe by replacing '+' and '/' characters
Dim signature As String = Convert.ToBase64String(hash).Replace("+", "-").Replace("/", "_")
Add the signature to the existing URI.
Return objURI.Scheme & "://" & objURI.Host & objURI.LocalPath & objURI.Query & "&signature=" & signature
End Function
End Module
Public Module Program
Sub Main()
Const keyString As String = "vNIXE0xscrmjlyV-12Nj_BvUPaw="
'The URL shown here is a static URL which should be already
'URL-encoded. In practice, you will likely have code
'which assembles your URL from user or web service input
'and plugs those values into its parameters.
Dim urlString As String = "http://maps.google.com/maps/api/geocode/json?address=New+York&sensor=false&client=clientID"
Console.WriteLine(GoogleUrlSigner.Sign(urlString, keyString))
End Sub
End Module
End Namespace