如何使用VBA Excel编码BASE64和SHA1 HMAC加密

如何使用VBA Excel编码BASE64和SHA1 HMAC加密,excel,vba,google-maps-api-3,Excel,Vba,Google Maps Api 3,我一直在互联网上搜索,此外,我还与谷歌的Servidesk人员就这个问题进行了联系。到目前为止没有运气 我正试图通过VBA中的web服务调用使用GoogleAPI进行指导。 我的代码运行得非常好,它从Web服务中给出了正确的结果。但是,如果我想每天发送数千个以上的请求,他们要求我在发送数据之前对数据进行加密 它们在下面有一个代码,但与VBA无关,仅适用于VB.net 这里有人熟悉VBA中的代码可用性吗?VBA是否有所需的库可供使用,并对代码或代码进行一些小的调整 Option Explicit

我一直在互联网上搜索,此外,我还与谷歌的Servidesk人员就这个问题进行了联系。到目前为止没有运气

我正试图通过VBA中的web服务调用使用GoogleAPI进行指导。 我的代码运行得非常好,它从Web服务中给出了正确的结果。但是,如果我想每天发送数千个以上的请求,他们要求我在发送数据之前对数据进行加密

它们在下面有一个代码,但与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