CryptoSys API examples VB6 to VB.NET

TDEA_HexMode

Encrypts or decrypts data represented as a hexadecimal string using a specified mode.

VB6/VBA

Debug.Print "Testing TDEA_HexMode ..."
Dim nRet As Long
Dim strOutput As String
Dim strInput As String
Dim strKey As String
Dim strIV As String
Dim bEncrypt As Boolean
Dim sCorrect As String
strInput = "5468697320736F6D652073616D706520636F6E74656E742E0808080808080808"
strKey = "737C791F25EAD0E04629254352F7DC6291E5CB26917ADA32"
strIV = "B36B6BFB6231084E"
sCorrect = "d76fd1178fbd02f84231f5c1d2a2f74a4159482964f675248254223daf9af8e4"
' Set strOutput to be same length as strInput
strOutput = String(Len(strInput), " ")
Debug.Print "KY=", strKey
Debug.Print "PT=", strInput
nRet = TDEA_HexMode(strOutput, strInput, strKey, True, "CBC", strIV)
Debug.Print "CT=", strOutput, nRet
Debug.Print "OK=", sCorrect
strInput = strOutput
nRet = TDEA_HexMode(strOutput, strInput, strKey, DECRYPT, "CBC", strIV)
Debug.Print "P'=", strOutput, nRet

Output

Testing TDEA_HexMode ...
KY=   737C791F25EAD0E04629254352F7DC6291E5CB26917ADA32
PT=   5468697320736F6D652073616D706520636F6E74656E742E0808080808080808
CT=   D76FD1178FBD02F84231F5C1D2A2F74A4159482964F675248254223DAF9AF8E4       0 
OK=   d76fd1178fbd02f84231f5c1d2a2f74a4159482964f675248254223daf9af8e4
P'=   5468697320736F6D652073616D706520636F6E74656E742E0808080808080808       0 

VB.NET

Console.WriteLine("Testing TDEA_HexMode ...")
''Dim nRet As Integer
Dim strOutput As String
Dim strInput As String
Dim strKey As String
Dim strIV As String
''Dim bEncrypt As Boolean
Dim sCorrect As String

strInput = "5468697320736F6D652073616D706520636F6E74656E742E0808080808080808"
strKey = "737C791F25EAD0E04629254352F7DC6291E5CB26917ADA32"
strIV = "B36B6BFB6231084E"
sCorrect = "d76fd1178fbd02f84231f5c1d2a2f74a4159482964f675248254223daf9af8e4"
' Set strOutput to be same length as strInput
''strOutput = String(Len(strInput), " ")

Console.WriteLine("KY=" & " " & strKey)
Console.WriteLine("PT=" & " " & strInput)
strOutput = Tdea.Encrypt(strInput, strKey, Mode.CBC, strIV)
Console.WriteLine("CT=" & " " & strOutput)
Console.WriteLine("OK=" & " " & sCorrect)

strInput = strOutput
strOutput = Tdea.Decrypt(strInput, strKey, Mode.CBC, strIV)
Console.WriteLine("P'=" & " " & strOutput)

[Contents]

[HOME]   [NEXT: TDEA_Update...]

Copyright © 2009-20 D.I. Management Services Pty Ltd. All rights reserved.