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.
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)
String to receive output in hexadecimal format.Long specifying the maximum number of characters to be received.String containing the message data in hexadecimal-encoded format.String containing the key in hexadecimal-encoded format.Long Option flags. Select one of:
long _stdcall HMAC_HexFromHex(char *szOutput, long nOutChars, const char *szMsgHex, const char *szKeyHex, long nOptions);
Long: If successful, the return value is the number of characters in the output string;
otherwise it returns a negative error code.
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).
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