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.
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)
String to receive output in hexadecimal format.Long specifying the maximum number of characters to be received.Byte array containing the message data in hexadecimal-encoded format.Byte array containing the key in hexadecimal-encoded format.Long Option flags. Select one of:
long _stdcall MAC_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.
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.
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