System.Security.Cryptography.HMACSHA1是Com可见的。我该怎么称呼ComputeHash?

时间:2012-08-20 11:10:59

标签: vba ms-access

我想在Microsoft Access

中创建一些文本的HMAC SHA1签名

.net对象System.Security.Cryptography.HMACSHA1是可见的,所以我想我可以使用它。

我可以创建对象并设置密钥,但是当我来调用计算函数来获取哈希时,我得到错误运行时错误5“无效的过程调用或参数”

Public Function sign(Key As String, Message As String)
    Dim asc, enc
    Dim MessageBytes() As bytes, HashBytes() As bytes
    Set asc = CreateObject("System.Text.UTF8Encoding")
    Set enc = CreateObject("System.Security.Cryptography.HMACSHA1")
    enc.Key = asc.GetBytes_4(Key)
    MessageBytes = asc.GetBytes_4(Message)
    HashBytes = enc.ComputeHash(MessageBytes)
    sign = EncodeBase64(HashBytes)
    Set asc = Nothing
    Set enc = Nothing
End Function

我从网络上复制了编码位,我注意到GetBytes已经转换为GetBytes_4。这个名字是不是很糟糕?我需要做类似于ComputeHash的事情吗?如果是这样的话(我试过_n,其中n = 1到6没有用)。

如果不是我做错了什么?

1 个答案:

答案 0 :(得分:0)

我在这个问题中找到了我的问题的答案

Base64 HMAC SHA1 String in VBA

我以为我曾尝试过enc.ComputeHash_2,但也许我没有,因为它似乎有效