【发布时间】:2012-08-20 19:26:58
【问题描述】:
我想在 Microsoft Access 中为某些文本创建 HMAC SHA1 签名
.net 对象 System.Security.Cryptography.HMACSHA1 是可见的,所以我想我可以使用它。
我可以创建对象并设置密钥,但是当我调用计算函数来获取哈希时,我收到错误运行时错误 5 "Invalid Procedure Call or Argument"
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 无济于事)。
如果不是我做错了什么?
【问题讨论】:
-
我找到了答案,见下文,但我没有找到关于如何使用名称修饰的任何好的解释。知道这仍然很有用