title: Cant use .GetBytes and .ComputeHash methods on VBA
body: <p>I want to translate a VB function to VBA. The function is using <code>"System.Text.UTF8Encoding"</code> and <code>"System.Security.Cryptography.HMACSHA256"</code></p>
  
  <p>Objects and their <code>".GetBytes"</code> and <code>".ComputeHash"</code> methods. </p>
  
  <p>I already added "System" and "mscorlib.dll" referrences to the VBA code, but I'm receiving "Invalid procedure call or argument" error. </p>
  
  <p>Here is my VB function:</p>
  
  <pre><code>Function HashString(ByVal StringToHash As String, ByVal HachKey As String) As String
      Dim myEncoder As New System.Text.UTF8Encoding
      Dim Key() As Byte = myEncoder.GetBytes(HachKey)
      Dim Text() As Byte = myEncoder.GetBytes(StringToHash)
      Dim myHMACSHA256 As New System.Security.Cryptography.HMACSHA256(Key)
      Dim HashCode As Byte() = myHMACSHA256.ComputeHash(Text)
      Dim hash As String = Replace(BitConverter.ToString(HashCode), "-", "")
      Return hash.ToLower
  End Function
  </code></pre>
  
  <p>And this is what I've already translated into VBA:</p>
  
  <pre><code>Function HashString(ByRef StringToHash As String, ByRef HachKey As String) As String
      Dim myEncoder As Object
      Dim myHMACSHA256 As Object
      Dim Key As Byte
      Dim Text As Byte
      Dim HashCode As Byte
      Dim hash As String
      Set myEncoder = CreateObject("System.Text.UTF8Encoding")
      Set myHMACSHA256 = CreateObject("System.Security.Cryptography.HMACSHA256")
      Key = myEncoder.GetBytes(HachKey)
      Text = myEncoder.GetBytes(StringToHash)
      HashCode = myHMACSHA256.ComputeHash(Text)
      hash = Replace(BitConverter.ToString(HashCode), "-", "")
      HashString = hash.ToLower
  End Function
  </code></pre>
  
  <p>Can anybody help on this? My first guess is that I'm using ".GetBytes" and ".ComputeHash" methods incorrectly</p>
  
  <p>Thanks in advance</p>