Creates a message authentication code (MAC) in hexadecimal format from hex-encoded data and a hex-encoded key.
VB6/VBA
Debug.Print "Testing MAC_HexFromHex ..." 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
Output
Testing MAC_HexFromHex ... CMAC-AES-128(K128, M128)=070a16b46b4d4144f79bdd9dd04a287c
VB.NET
Console.WriteLine("Testing MAC_HexFromHex ...") Dim strKeyHex As String Dim strMsgHex As String Dim strMAC As String ''Dim nRet As Integer ' 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, " ") strMAC = Mac.HexFromHex(strMsgHex, strKeyHex, MacAlgorithm.CmacAes128) If strMAC.Length > 0 Then Console.WriteLine("CMAC-AES-128(K128, M128)=" & strMAC) Else Console.WriteLine("Error") End If
[Contents]