CryptoSys API Library Manual

SHA1_HmacHex

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

VB6/VBA Syntax

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

nRet = SHA1_Hmac(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 SHA1_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

Sha1.Hmac Method (String, String)

COM/ASP Equivalent

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

See sha1.HmacHex.

Remarks

The string variable strDigest must be at least 40 (API_MAX_SHA1_CHARS) characters long (41 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

'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<SHA> >(
'"303132333435363738393a3b3c3d3e3f40414243",
'"Sample #2",
'"0922d3405faa3d194f82a45830737d5cc6c75d24");

    Dim nRet As Long
    Dim strDigest As String * 40
    Dim strMessage As String
    Dim sHexMsg As String
    Dim sCorrect As String
    
    sCorrect = "0922d3405faa3d194f82a45830737d5cc6c75d24"
    
    ' Convert data to hex format
    sHexMsg = cnvHexStrFromString("Sample #2")
    nRet = SHA1_HmacHex(strDigest, sHexMsg, "303132333435363738393a3b3c3d3e3f40414243")
    Debug.Print "Digest =" & strDigest
    Debug.Print "Correct=" & sCorrect
    Debug.Assert (strDigest = sCorrect)

This should result in output as follows:

Digest =0922d3405faa3d194f82a45830737d5cc6c75d24
Correct=0922d3405faa3d194f82a45830737d5cc6c75d24

See Also

SHA1_Hmac

[Contents] [Index]

[HOME]   [NEXT: SHA1_Init...]

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