CryptoSys API Library Manual

MAC_HexFromHex

MAC_HexFromHex creates a message authentication code (MAC) in hexadecimal format from hex-encoded data and a hex-encoded key. The MAC algorithm to use is passed in the options parameter.

VB6/VBA Syntax

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

nRet = MAC_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] Byte array containing the message data in hexadecimal-encoded format.
strKeyHex
[in] Byte array containing the key in hexadecimal-encoded format.
nOptions
[in] Long Option flags. Select one of:
HMAC algorithms:
API_HASH_SHA1 (0) to use the SHA-1 hash algorithm (default)
API_HASH_MD5 to use the MD5 algorithm
API_HASH_RMD160 to use the RIPEMD-160 algorithm
API_HASH_SHA224 to use the SHA-224 algorithm
API_HASH_SHA256 to use the SHA-256 algorithm
API_HASH_SHA384 to use the SHA-384 algorithm
API_HASH_SHA512 to use the SHA-512 algorithm
CMAC algorithms:
API_CMAC_TDEA to use the Triple DES (DES-EDE) block cipher
API_CMAC_AES128 to use the AES-128 block cipher
API_CMAC_AES192 to use the AES-192 block cipher
API_CMAC_AES256 to use the AES-256 block cipher

C/C++ Syntax

long _stdcall MAC_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

Mac.HexFromHex Method

Remarks

Specify a zero nOutChars or a NULL strOutput parameter to find out the required length of the output string. The maximum number of characters is API_MAX_HASH_CHARS. C/C++ users should add one to this value before allocating memory. The final digest will be truncated to the specified length if less than the expected size. Only lower-case letters [a-f] are used in the output. MD2 is not available with the HMAC functions.

Example

Dim strKeyHex As String
Dim strMsgHex As String
Dim strMAC As String
Dim nRet As Long

' SP800-38: compute CMAC_AES-128 on Example 2: Mlen = 128
strKeyHex = "2b7e151628aed2a6abf7158809cf4f3c"
strMsgHex = "6bc1bee22e409f96e93d7e117393172a"
' Output MAC size in hex is double the block length of the cipher
strMAC = String(API_BLK_AES_BYTES * 2, " ")
nRet = MAC_HexFromHex(strMAC, Len(strMAC), strMsgHex, strKeyHex, API_CMAC_AES128)
If nRet > 0 Then
    Debug.Print "CMAC-AES-128(K128, M128)=" & Left$(strMAC, nRet)
Else
    Debug.Print "Error code " & nRet
End If

This should produce the output

CMAC-AES-128(K128, M128)=070a16b46b4d4144f79bdd9dd04a287c

See Also

MAC_Bytes MAC_HexFromBytes

[Contents] [Index]

[HOME]   [NEXT: MD5_AddBytes...]

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