CryptoSys API Library Manual

SHA2_HmacHex

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

VBA/VB6 Syntax

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

nRet = SHA2_HmacHex(strDigest, strHexData, strHexKey)

C/C++ Syntax

long __stdcall SHA2_HmacHex(char *szDigest, const char *sHexText, const char *sHexKey);

Parameters

szDigest
[out] variable of sufficient length to receive the message digest in hex format.
sHexText
[in] containing the text of the message in hexadecimal format.
sHexKey
[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

Sha256.Hmac Method (String, String)

COM/ASP Equivalent

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

See sha256.HmacHex.

Remarks

szDigest must be at least 64 (API_MAX_SHA2_CHARS) characters long (65 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

'Example from Wei Dai's Crypto++ test vectors
'fipstest.cpp - written and placed in the public domain by Wei Dai
'From http://trolocsis.com/crypto++/fipstest_8cpp-source.html
'MAC_KnownAnswerTest<HMAC<SHA256> >(
'"303132333435363738393a3b3c3d3e3f40414243",
'"abc",
'"D28363F335B2DAE468793A38680DEA9F7FB8BE1DCEDA197CDB3B1CB59A9F6422");

    Dim nRet As Long
    Dim strDigest As String * 64
    Dim strMessage As String
    Dim sHexMsg As String
    Dim sCorrect As String
    
    sCorrect = "d28363f335b2dae468793a38680dea9f7fb8be1dceda197cdb3b1cb59a9f6422"
    
    ' Convert data to hex format
    sHexMsg = cnvHexStrFromString("abc")
    nRet = SHA2_HmacHex(strDigest, sHexMsg, "303132333435363738393a3b3c3d3e3f40414243")
    Debug.Print "Digest =" & strDigest
    Debug.Print "Correct=" & sCorrect
    Debug.Assert (strDigest = sCorrect)

This should result in output as follows:

Digest =d28363f335b2dae468793a38680dea9f7fb8be1dceda197cdb3b1cb59a9f6422
Correct=d28363f335b2dae468793a38680dea9f7fb8be1dceda197cdb3b1cb59a9f6422

See Also

SHA2_Hmac

[Contents] [Index]

[PREV: SHA2_Hmac...]   [Contents]   [Index]   
   [NEXT: SHA2_Init...]

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