CryptoSys PKI Toolkit Manual

HMAC_HexFromHex

HMAC_HexFromHex creates a keyed-hash based message authentication code (HMAC) in hexadecimal format from data in hexadecimal-encoded strings. The hash algorithm to use is passed in the options parameter.

VB6/VBA Syntax

Public Declare Function HMAC_HexFromHex Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strMsgHex As String, ByVal strKeyHex As String, ByVal nOptions As Long) As Long

nRet = HMAC_HexFromHex(strOutput, nOutChars, strMsgHex, strKeyHex, nOptions)

Parameters

strOutput
[out] String to receive output in hexadecimal format.
nOutChars
[in] Long specifying the maximum number of characters to be received.
strMsgHex
[in] String containing the message data in hexadecimal-encoded format.
strKeyHex
[in] String containing the key in hexadecimal-encoded format.
nOptions
[in] Long Option flags. Select one of:
PKI_HASH_SHA1 (0) to use the SHA-1 algorithm (default)
PKI_HASH_MD5 to use the MD5 algorithm
PKI_HASH_SHA256 to use the SHA-256 algorithm
PKI_HASH_SHA384 to use the SHA-384 algorithm
PKI_HASH_SHA512 to use the SHA-512 algorithm
PKI_HASH_SHA224 to use the SHA-224 algorithm

C/C++ Syntax

long _stdcall HMAC_HexFromHex(char *szOutput, long nOutChars, const char *szMsgHex, const char *szKeyHex, long nOptions);

Returns (VB6/C)

Long: If successful, the return value is the number of characters in the output string; otherwise it returns a negative error code.

.NET Equivalent

Hmac.HexFromHex Method

Remarks

Specify a zero nOutChars or a NULL strOutput parameter to find out the required length of the output string, or use the appropriate PKI_xxx_CHARS constant. The maximum number of characters is PKI_MAX_HASH_CHARS. C/C++ users should add one to this value when allocating memory. The final digest will be truncated to the specified length if less than the expected size. MD2 is not available with the HMAC functions.

Note the order of parameters here (data, key) is different from the usual order HMAC(key, text).

Example

Dim strDigest As String
Dim nRet As Long
Dim strData As String
Dim strKey As String
' Ref: RFC 2202 and RFC 4231
' Test Case 1
' Key =  0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
'        0b0b0b0b                    (20 bytes)
' Data = 4869205468657265            ("Hi There")

' Compute HMAC-SHA-1
strDigest = String(PKI_SHA1_CHARS, " ")
strData = "4869205468657265"
strKey = "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
nRet = HMAC_HexFromHex(strDigest, Len(strDigest), strData, strKey, PKI_HASH_SHA1)
Debug.Print strDigest
' Compute HMAC-SHA-256
strDigest = String(PKI_SHA256_CHARS, " ")
nRet = HMAC_HexFromHex(strDigest, Len(strDigest), strData, strKey, PKI_HASH_SHA256)
Debug.Print strDigest

The above example should produce the following output:

b617318655057264e28bc0b6fb378c8ef146be00
b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7

See Also

HMAC_Bytes HMAC_HexFromBytes

[Contents] [Index]

[HOME]   [NEXT: PEM_FileFromBinFile...]

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