CryptoSys API Library Manual

MD5_HmacHex

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.

VB6/VBA 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)

Parameters

strDigest
[out] String variable of sufficient length to receive the message digest in hex format.
strHexData
[in] String containing the text of the message in hexadecimal format.
strHexKey
[in] String containing the key in hexadecimal format.

C/C++ Syntax

long _stdcall MD5_HmacHex(char *strDigest, const char *sHexText, const char *strHexKey);

Returns (VB6/C)

Long: 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

strDigest must be at least 32 (API_MAX_MD5_CHARS) characters long (33 in a C program). strData and strKey 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]

[HOME]   [NEXT: MD5_Init...]

Copyright © 2001-9 D.I. Management Services Pty Ltd. All rights reserved.