小编Ale*_*x.M的帖子

来自 SHA256 和 HMACSHA256 函数的 Vba Excel“自动化错误”

目前在我的代码中出现自动化错误(注意,此错误仅发生在 Windows 10 上)

Set oUTF = CreateObject("System.Text.UTF8Encoding")

Set oEnc = CreateObject("System.Security.Cryptography.SHA256Managed")
Run Code Online (Sandbox Code Playgroud)

这是完整的功能

Function HMACSHA256(strToSign As String, strKey() As Byte)
Dim lngLoop As Long
Dim oUTF, oEnc
Dim HMAC() As Byte
Dim lastrow As Long

On Error GoTo err_handler

Set oUTF = CreateObject("System.Text.UTF8Encoding")
Set oEnc = CreateObject("System.Security.Cryptography.HMACSHA256")
oEnc.key = strKey
HMAC = oEnc.ComputeHash_2(oUTF.GetBytes_4(strToSign)) 

HMACSHA256 = HMAC

Exit Function

err_handler:
    Worksheets("Log Sheet").Cells(lastrow, 4) = "Fail"
    Worksheets("Log Sheet").Cells(lastrow, 5) = Err.Description
    MsgBox Err.Description, vbCritical

End Function
Run Code Online (Sandbox Code Playgroud)

通过我的测试和研究,我发现这些行上的这个错误与 .netframework 4.6 版有关。安装 .netframework 的 …

excel vba

5
推荐指数
1
解决办法
6654
查看次数

标签 统计

excel ×1

vba ×1