Adds an array of bytes to be authenticated in the MAC context.
Public Declare Function MAC_AddBytes Lib "diCryptoSys.dll" (ByVal hContext As Long, ByRef lpData As Byte, ByVal nDataLen As Long) As Long
nRet = MAC_AddBytes(hContext, abData(0), nDataLen)
long __stdcall MAC_AddBytes(long hContext, const void *lpData, long nDataLen);
If successful, the return value is 0; otherwise it returns a non-zero error code.
Public Function macAddBytes
(hContext As Long, lpData() As Byte) As Long
Public Function macAddString(hContext As Long, szData As String) As Long
Mac.AddData Method (Byte[])
Mac.AddData Method (String)
int crsysapi::Mac::AddData (bvec_t data)
int crsysapi::Mac::AddData (std::string s)
The handle hContext to the context must have been set up with a
prior call to MAC_Init
.
The MAC_AddBytes
function may be called many times before creating
the final message digest with MAC_Final
.
VBA users can use the more convenient wrapper functions macAddBytes
and macAddString
.
' Test case 4 from RFC 2202 and RFC 4231 ' key = 0x0102030405060708090a0b0c0d0e0f10111213141516171819 ' key_len 25 ' data = 0xcd repeated 50 times ' data_len = 50 Dim hContext As Long Dim r As Long Dim lpKey() As Byte Dim lpMsg10() As Byte Dim lpDigest() As Byte Dim i As Long lpKey = cnvBytesFromHexStr("0102030405060708090a0b0c0d0e0f10111213141516171819") lpMsg10 = cnvBytesFromHexStr("cdcdcdcdcdcdcdcdcdcd") ' 0xcd repeated 10 times ' HMAC-SHA-1 hContext = macInit(lpKey, API_HMAC_SHA1) Debug.Print "macInit returns 0x" & Hex(hContext) & " (expected nonzero)" For i = 1 To 5 r = macAddBytes(hContext, lpMsg10) Debug.Print "macAddBytes returns " & r Next lpDigest = macFinal(hContext) Debug.Print "MAC=" & cnvHexStrFromBytes(lpDigest) Debug.Print "OK= " & "4c9007f4026250c6bc8414f9bf50c86c2d7235da" ' HMAC-SHA-256 hContext = macInit(lpKey, API_HMAC_SHA256) Debug.Print "macInit returns 0x" & Hex(hContext) & " (expected nonzero)" For i = 1 To 5 r = macAddBytes(hContext, lpMsg10) 'Debug.Print "macAddBytes returns " & r Next lpDigest = macFinal(hContext) Debug.Print "MAC=" & cnvHexStrFromBytes(lpDigest) Debug.Print "OK= " & "82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b" Dim strData As String Dim strKey As String ' Test case 2 from RFC 2202 and RFC 4231 strData = "what do ya want for nothing?" strKey = "Jefe" lpKey = StrConv(strKey, vbFromUnicode) hContext = macInit(lpKey, API_HMAC_SHA512) ' Split input into parts r = macAddString(hContext, "what do ya") r = macAddString(hContext, " want for ") r = macAddString(hContext, "nothing?") lpDigest = macFinal(hContext) Debug.Print "MAC=" & cnvHexStrFromBytes(lpDigest) Debug.Print "OK =" _ & "164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea250554" _ & "9758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737"