Carries out the AES transformation function on a hexadecimal string according to the direction and mode set up by an earlier call to AES128_Init or AES128_InitHex.
VB6/VBA
Debug.Print "Testing AES128_UpdateHex ..." Dim nRet As Long Dim hContext As Long Dim sBlock As String Dim strHexKey As String Dim strIV As String Dim sNext As String Dim sLast As String Dim sCorrect As String Dim j As Integer ' cbc_e_m.txt ' KEYSIZE=128 I=2 ' KEY=93286764A85146730E641888DB34EB47 ' IV=192D9B3AA10BB2F7846CCBA0085C657A ' PT=983BF6F5A6DFBCDAA19370666E83A99A ' CT=40D8DAF6D1FDA0A073B3BD18B7695D2E strHexKey = "93286764A85146730E641888DB34EB47" strIV = "192D9B3AA10BB2F7846CCBA0085C657A" sBlock = "983BF6F5A6DFBCDAA19370666E83A99A" sCorrect = "40D8DAF6D1FDA0A073B3BD18B7695D2E" Debug.Print "AES Monte Carlo CBC Mode Encrypt:" Debug.Print "KY=", strHexKey Debug.Print "IV=", strIV Debug.Print "PT=", sBlock hContext = AES128_InitHex(strHexKey, ENCRYPT, "CBC", strIV) If hContext = 0 Then MsgBox "Failed to set context", vbCritical Exit Sub End If ' Do 10,000 times sNext = sBlock For j = 0 To 9999 sBlock = sNext nRet = AES128_UpdateHex(hContext, sBlock) If j = 0 Then sNext = strIV Else sNext = sLast End If sLast = sBlock Next Debug.Print "CT=", sBlock Debug.Print "OK=", sCorrect nRet = AES128_Final(hContext) Debug.Assert (sCorrect = sBlock)
Output
Testing AES128_UpdateHex ... AES Monte Carlo CBC Mode Encrypt: KY= 93286764A85146730E641888DB34EB47 IV= 192D9B3AA10BB2F7846CCBA0085C657A PT= 983BF6F5A6DFBCDAA19370666E83A99A CT= 40D8DAF6D1FDA0A073B3BD18B7695D2E OK= 40D8DAF6D1FDA0A073B3BD18B7695D2E
VB.NET
Console.WriteLine("Testing AES128_UpdateHex ...") Dim nRet As Integer ''Dim hContext As Integer Dim sBlock As String Dim strHexKey As String Dim strIV As String Dim sNext As String Dim sLast As String Dim sCorrect As String Dim j As Integer Dim oAes128 As Aes128 = Aes128.Instance() ' cbc_e_m.txt ' KEYSIZE=128 I=2 ' KEY=93286764A85146730E641888DB34EB47 ' IV=192D9B3AA10BB2F7846CCBA0085C657A ' PT=983BF6F5A6DFBCDAA19370666E83A99A ' CT=40D8DAF6D1FDA0A073B3BD18B7695D2E strHexKey = "93286764A85146730E641888DB34EB47" strIV = "192D9B3AA10BB2F7846CCBA0085C657A" sBlock = "983BF6F5A6DFBCDAA19370666E83A99A" sCorrect = "40D8DAF6D1FDA0A073B3BD18B7695D2E" Console.WriteLine("AES Monte Carlo CBC Mode Encrypt:") Console.WriteLine("KY=" & " " & strHexKey) Console.WriteLine("IV=" & " " & strIV) Console.WriteLine("PT=" & " " & sBlock) nRet = oAes128.InitEncrypt(strHexKey, Mode.CBC, strIV) If nRet <> 0 Then MsgBox("Failed to set context", vbCritical) Exit Sub End If ' Do 10,000 times sNext = sBlock sLast = "" For j = 0 To 9999 sBlock = sNext sBlock = oAes128.Update(sBlock) If j = 0 Then sNext = strIV Else sNext = sLast End If sLast = sBlock Next Console.WriteLine("CT=" & " " & sBlock) Console.WriteLine("OK=" & " " & sCorrect) oAes128.Dispose() Debug.Assert(sCorrect.ToLower = sBlock.ToLower)
[Contents]