CryptoSys API Library Manual

Example: Tdea.Decrypt  Tdea.Encrypt  (2)

[VB6 equivalent: TDEA_Bytes]

Dim strInput As String
Dim strKey As String
Dim sCorrect As String
Dim abKey() As Byte
Dim abOutput() As Byte
Dim abData() As Byte

' Define test vectors in hex
strKey = "0123456789abcdeffedcba987654321089abcdef01234567"
strInput = "0123456789abcde70123456789abcde7"
sCorrect = "de0b7c06ae5e0ed5de0b7c06ae5e0ed5"

' Convert to byte arrays and compute lengths
abKey = Cnv.FromHex(strKey)
abData = Cnv.FromHex(strInput)

' Dimension array for output

Console.WriteLine("KY=" & " " & Cnv.ToHex(abKey))
Console.WriteLine("PT=" & " " & Cnv.ToHex(abData))
' Encrypt in one-off process
abOutput = Tdea.Encrypt(abData, abKey, Mode.ECB, Nothing)
Console.WriteLine("CT=" & " " & Cnv.ToHex(abOutput))
Console.WriteLine("OK=" & " " & sCorrect)
Debug.Assert(sCorrect.ToUpper = Cnv.ToHex(abOutput))

' Now decrypt back
abOutput = Tdea.Decrypt(abData, abKey, Mode.ECB, Nothing)
Console.WriteLine("P'=" & " " & Cnv.ToHex(abData))
Debug.Assert(strInput.ToUpper = Cnv.ToHex(abData))

See Also:
Tdea.Decrypt Method (Byte[], Byte[], Mode, Byte[])
Tdea.Encrypt Method (Byte[], Byte[], Mode, Byte[])

[Contents] [Index]

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

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