CryptoSys API Library Manual

MD5_HmacHex

Is a keyed-hash function that provides message authentication using the HMAC algorithm and the MD5 hash function, passing its arguments in hexadecimal format.

VBA/VB6 Syntax

Public Declare Function MD5_HmacHex Lib "diCryptoSys.dll" (ByVal strDigest As String, ByVal strHexData As String, ByVal strHexKey As String) As Long

nRet = MD5_HmacHex(strDigest, strHexData, strHexKey)

C/C++ Syntax

long __stdcall MD5_HmacHex(char *szDigest, const char *szHexText, const char *szHexKey);

Parameters

szDigest
[out] variable of sufficient length to receive the message digest in hex format.
szHexText
[in] containing the text of the message in hexadecimal format.
szHexKey
[in] containing the key in hexadecimal format.

Returns (VBA/C)

If successful, the return value is 0; otherwise it returns a non-zero error code.

.NET Equivalent

Md5.Hmac Method (String, String)

COM/ASP Equivalent

md5.HmacHex
Public Function HmacHex(ByVal strHexText As String, ByVal strHexKey As String) As String

See md5.HmacHex.

Remarks

szDigest must be at least 32 (API_MAX_MD5_CHARS) characters long (33 in a C program). szData and szKey are expected to be an even number of characters long, i.e. representing complete byte values. Any trailing odd character will be ignored.

Example

'    Test No 1. from RFC 2104
'    key =         0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
'    key_len =     16 bytes
'    Data = "Hi There"
'    data_len =    8  bytes
'    digest =      0x9294727a3638bb1c13f48ef8158bfc9d

    Dim nRet As Long
    Dim strDigest As String * 32
    Dim strMessage As String
    Dim sHexMsg As String
    Dim sCorrect As String
    
    sCorrect = "9294727a3638bb1c13f48ef8158bfc9d"
    
    ' Convert data to hex format
    sHexMsg = cnvHexStrFromString("Hi There")
    nRet = MD5_HmacHex(strDigest, sHexMsg, "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b")
    Debug.Print "Digest =" & strDigest
    Debug.Print "Correct=" & sCorrect
    Debug.Assert (strDigest = sCorrect)

This should result in output as follows:

Digest =9294727a3638bb1c13f48ef8158bfc9d
Correct=9294727a3638bb1c13f48ef8158bfc9d

See Also

MD5_Hmac

[Contents] [Index]

[PREV: MD5_Hmac...]   [Contents]   [Index]   
   [NEXT: MD5_Init...]

Copyright © 2001-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-01-07T07:42:00Z.