CryptoSys API Library Manual

Example: Tdea.Dispose  Tdea.ErrCode  Tdea.InitEncrypt  Tdea.Instance  Tdea.Update 

[VB6 equivalent: TDEA_Update]

Dim nRet As Integer
Dim sCorrect As String
Dim j As Integer
Dim abKey() As Byte
Dim abInitV() As Byte
Dim aBlock() As Byte
Dim aNext() As Byte
Dim aLast() As Byte
Dim oTdea As Tdea = Tdea.Instance()

aBlock = System.Text.Encoding.Default.GetBytes("Now is t")
abKey = Cnv.FromHex( _
    "0123456789abcdef23456789abcdef01456789abcdef0123")
abInitV = Cnv.FromHex("1234567890abcdef")
sCorrect = "cb191f85d1ed8439"

Console.WriteLine("TDEA Monte Carlo TCBC Mode Encrypt:")
Console.WriteLine("KY=" & " " & Cnv.ToHex(abKey))
Console.WriteLine("IV=" & " " & Cnv.ToHex(abInitV))
Console.WriteLine("PT=" & " " & Cnv.ToHex(aBlock))

nRet = oTdea.InitEncrypt(abKey, Mode.CBC, abInitV)
If nRet <> 0 Then
    nRet = oTdea.ErrCode()
    Console.WriteLine("TDEA_Init Failed: " & General.ErrorLookup(nRet))
    Exit Sub
End If
' [VB.NET] We must treat byte arrays differently in VB.NET...
ReDim aNext(aBlock.Length - 1)
ReDim aLast(aBlock.Length - 1)
Buffer.BlockCopy(aBlock, 0, aNext, 0, aBlock.Length)
' Do 10,000 times
For j = 0 To 9999
    Buffer.BlockCopy(aNext, 0, aBlock, 0, aNext.Length)
    aBlock = oTdea.Update(aBlock)
    If j = 0 Then
        Buffer.BlockCopy(abInitV, 0, aNext, 0, abInitV.Length)
    Else
        Buffer.BlockCopy(aLast, 0, aNext, 0, aLast.Length)
    End If
    Buffer.BlockCopy(aBlock, 0, aLast, 0, aBlock.Length)
Next
Console.WriteLine("CT=" & " " & Cnv.ToHex(aBlock))
Console.WriteLine("OK=" & " " & sCorrect)
oTdea.Dispose()

Debug.Assert(sCorrect.ToUpper = Cnv.ToHex(aBlock))

See Also:
Tdea.Update Method (Byte[])

[Contents] [Index]

[PREV: Example: Tdea.Decrypt ...]   [Contents]   [Index]   
   [NEXT: Example: Wipe.Data ...]

Copyright © 2001-23 D.I. Management Services Pty Ltd. All rights reserved. Generated 2023-05-20T13:01:10Z.