0

I want to create an HMAC SHA1 signature of some text in Microsoft Access

The .net object System.Security.Cryptography.HMACSHA1 is com visible, so I thought I could use that.

I can create the object and set the key, but when I come to call the compute function to get the hash, I am getting the error run time error 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

I copied the Encoding bit from the web and I note there that GetBytes has transmuted into GetBytes_4. Is this name mangling? and do I need to do something similar to ComputeHash? and if so what (I tried _n where n = 1 to 6 to no avail).

If not What am I doing wrong?

akc42
  • 4,893
  • 5
  • 41
  • 60
  • I found an answer, see below, but I haven't found any good explanation of how to use name mangling. That would still be useful to know – akc42 Aug 20 '12 at 13:13

1 Answers1

0

I found the answer to my question in this question

Base64 HMAC SHA1 String in VBA

I thought I had tried enc.ComputeHash_2, but maybe I didn't because it seems to work

Community
  • 1
  • 1
akc42
  • 4,893
  • 5
  • 41
  • 60