Is a keyed-hash function that provides message authentication using the HMAC algorithm and the MD5 hash function.
Public Declare Function MD5_Hmac Lib "diCryptoSys.dll"
(ByVal strDigest As String, ByRef abData As Byte, ByVal nDataLen As Long,
ByRef abKey As Byte, ByVal nKeyLen As Long) As Long
nRet = MD5_Hmac(strDigest, abData(0), nDataLen, abKey(0), nKeyLen)
String variable of sufficient length to
receive the message digest in hex format.Byte array containing the text of the message.Long containing the number of bytes in the arrayByte array containing the key.Long containing the number of bytes in the key
long _stdcall MD5_Hmac(char *strDigest,
const unsigned char *textBytes, long textLen,
const unsigned char *keyBytes, long keyLen);
Long: If successful, the return value is 0;
otherwise it returns a non-zero error code.
Md5.Hmac Method (Byte[], Byte[])
strDigest must be at least 32 (API_MAX_MD5_CHARS) characters long (33 in a C program).
VB6/VBA users: Note the '(0)' in abData(0) and abKey(0).
This example reproduces the three test vectors from RFC 2104.
Dim nRet As Long
Dim abData() As Byte
Dim abKey() As Byte
Dim i As Integer
Dim nDataLen As Long, nKeyLen As Long
Dim strDigest As String * 32
' Test No 1.
' Set key = 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
ReDim abKey(15)
For i = 0 To 15
abKey(i) = &HB
Next
' Convert string to byte array
abData() = StrConv("Hi There", vbFromUnicode)
nDataLen = UBound(abData) + 1
' Create HMAC digest
nRet = MD5_Hmac(strDigest, abData(0), nDataLen, abKey(0), 16)
Debug.Print 1; nRet; strDigest
' Test No 2.
abKey() = StrConv("Jefe", vbFromUnicode)
nKeyLen = UBound(abKey) + 1
abData() = StrConv("what do ya want for nothing?", vbFromUnicode)
nDataLen = UBound(abData) + 1
nRet = MD5_Hmac(strDigest, abData(0), nDataLen, abKey(0), nKeyLen)
Debug.Print 2; nRet; strDigest
' Test No 3.
ReDim abKey(15)
For i = 0 To 15
abKey(i) = &HAA
Next
ReDim abData(49)
For i = 0 To 49
abData(i) = &HDD
Next
nRet = MD5_Hmac(strDigest, abData(0), 50, abKey(0), 16)
Debug.Print 3; nRet; strDigest
This should result in output as follows:
1 0 9294727a3638bb1c13f48ef8158bfc9d 2 0 750c783e6ab0b503eaa86e310a5db738 3 0 56be34521d144c88dbb8c733f0e8b3f6
-