如何使用VBA Excel编码BASE64和SHA1 HMACencryption

我一直在search整个互联网,此外还与Google的servidedesk人联系在这个问题上。 目前还没有运气。

我正尝试通过VBA中的Web服务调用使用Google API for Directions。 我的代码工作得非常好,它从web服务提供正确的结果。 但是,他们要求我发送数据之前encryption数据,如果我想发送数以千计的每日请求。

他们在下面有一个代码,但不涉及到VBA和VB.net。

有人在这里熟悉这个代码在VBA中的可用性吗? VBA是否有必要的库来使用一些小的代码调整或?

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