Ich möchte eine VB-Funktion in VBA übersetzen. Die Funktion verwendet "System.Text.UTF8Encoding"
und "System.Security.Cryptography.HMACSHA256"
Cant Verwendung. GetBytes und. ComputeHash-Methoden auf VBA
Objekte und ihre ".GetBytes"
und ".ComputeHash"
Methoden.
Ich habe bereits "System" und "Mscorlib.dll" References zum VBA-Code hinzugefügt, aber ich erhalte "ungültiger Prozeduraufruf oder Argument" Fehler.
Hier ist meine VB-Funktion:
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
Und das ist, was ich schon in VBA übersetzt habe:
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
auf diese Kann jemand helfen? Meine erste Vermutung ist, dass ich im Voraus „.GetBytes“ und „.ComputeHash“ Methoden falsch
Dank bin mit
Danke, arbeitete wie ein Charme :) – Behnam2016