【问题标题】:System.Security.Cryptography.HMACSHA1 is Com visible. How should I call ComputeHash?System.Security.Cryptography.HMACSHA1 是 Com 可见的。我应该如何调用 ComputeHash?
【发布时间】: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 无济于事)。

如果不是我做错了什么?

【问题讨论】:

  • 我找到了答案,见下文,但我没有找到关于如何使用名称修饰的任何好的解释。知道这仍然很有用

标签: vba ms-access


【解决方案1】:

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

Base64 HMAC SHA1 String in VBA

我以为我尝试过 enc.ComputeHash_2,但也许我没有尝试过,因为它似乎可以工作

【讨论】:

  • 您有没有发现是否有一种好方法可以查找用于 _# 后缀的正确数字?
  • @ncovox - 不抱歉。我不记得我为什么问这个问题以及它是针对哪一段代码
猜你喜欢
  • 1970-01-01
  • 2010-10-31
  • 1970-01-01
  • 2010-10-13
  • 2011-04-08
  • 2011-10-14
  • 2013-02-04
  • 1970-01-01
  • 2011-01-15
相关资源
最近更新 更多