相关疑难解决方法(0)

VBA中的Base64 HMAC SHA1字符串

我正在尝试将ASP/VBScript OAuth库转换为VBA.其中一个挑战是这行代码:

Get_Signature = b64_hmac_sha1(strSecret, strBaseSignature)
Run Code Online (Sandbox Code Playgroud)

该函数b64_hmac_sha1实际上是JavaScript库中包含的函数.在我看来,从VBA调用JavaScript函数是相当不切实际的.

因为我对加密知之甚少,所以我甚至不清楚这个b64_hmac_sha1功能是做什么的.HMAC SHA1与SHA1不同吗?

我怀疑我可以在网上找到一些VBA代码来做我需要做的事情,如果我只是理解这个功能实际上在做什么.如果我找不到现有的函数,我可能会编写一个使用.NET Cryptography库的函数(如果你知道如何,你可以从VBA调用.NET加密库).

我不是在找人将这个JavaScript转换为VBA.我只是想了解这个b64_hmac_sha1函数输出的是什么,所以我可以尝试找到在VBA中实现相同输出的方法(如果可能的话).

此网站上提供了此JavaScript库的副本.您必须向下滚动浏览VBScript到JavaScript部分. http://solstice.washington.edu/solstice/ASP_Signing_REST_Example

编辑1:
好的,所以这里是我写完和使用的函数:

Public Function Base64_HMACSHA1(ByVal sTextToHash As String, ByVal sSharedSecretKey As String)

    Dim asc As Object, enc As Object
    Dim TextToHash() As Byte
    Dim SharedSecretKey() As Byte
    Set asc = CreateObject("System.Text.UTF8Encoding")
    Set enc = CreateObject("System.Security.Cryptography.HMACSHA1")

    TextToHash = asc.Getbytes_4(sTextToHash)
    SharedSecretKey = asc.Getbytes_4(sSharedSecretKey)
    enc.Key = SharedSecretKey

    Dim bytes() As Byte
    bytes = enc.ComputeHash_2((TextToHash))
    Base64_HMACSHA1 = EncodeBase64(bytes)
    Set asc = Nothing
    Set enc = Nothing

End Function

Private Function …
Run Code Online (Sandbox Code Playgroud)

javascript encryption vba hmacsha1

4
推荐指数
1
解决办法
9187
查看次数

标签 统计

encryption ×1

hmacsha1 ×1

javascript ×1

vba ×1