我想在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没有用)。
如果不是我做错了什么?
答案 0 :(得分:0)