CryptoSys PKI examples VB6 to VB.NET

TDEA_HexMode

Encrypts/decrypts a hex-encoded string using Triple DES with hex-encoded key and IV.

VB6/VBA

Debug.Print "Testing TDEA_HexMode ..."
Dim nRet As Long
Dim sOutput As String
Dim sInput As String
Dim sKey As String
Dim sInitV As String
Dim sCorrect As String

sInput = "5468697320736F6D652073616D706520636F6E74656E742E0808080808080808"
'         T h i s _ s o m e _ s a m p e _ c o n t e n t . (padding 8 x 08)
sKey = "737C791F25EAD0E04629254352F7DC6291E5CB26917ADA32"
sInitV = "B36B6BFB6231084E"
sCorrect = "d76fd1178fbd02f84231f5c1d2a2f74a4159482964f675248254223daf9af8e4"
' Set sOutput to be same length as sInput
sOutput = String(Len(sInput), " ")

Debug.Print "KY=" & sKey
Debug.Print "PT=" & sInput
nRet = TDEA_HexMode(sOutput, sInput, sKey, ENCRYPT, "CBC", sInitV)
Debug.Print "CT=" & sOutput, nRet
Debug.Print "OK=" & sCorrect

sInput = sOutput
nRet = TDEA_HexMode(sOutput, sInput, sKey, DECRYPT, "CBC", sInitV)
Debug.Print "P'=" & sOutput, 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 sOutput As String
Dim sInput As String
Dim sKey As String
Dim sInitV As String
Dim sCorrect As String

sInput = "5468697320736F6D652073616D706520636F6E74656E742E0808080808080808"
'         T h i s _ s o m e _ s a m p e _ c o n t e n t . (padding 8 x 08)
sKey = "737C791F25EAD0E04629254352F7DC6291E5CB26917ADA32"
sInitV = "B36B6BFB6231084E"
sCorrect = "d76fd1178fbd02f84231f5c1d2a2f74a4159482964f675248254223daf9af8e4"
' Set sOutput to be same length as sInput
''sOutput = String(Len(sInput), " ")

Console.WriteLine("KY=" & sKey)
Console.WriteLine("PT=" & sInput)
sOutput = Tdea.Encrypt(sInput, sKey, Mode.CBC, sInitV, EncodingBase.Base16)
Console.WriteLine("CT=" & sOutput & " " & General.ErrorCode)
Console.WriteLine("OK=" & sCorrect)

sInput = sOutput
sOutput = Tdea.Decrypt(sInput, sKey, Mode.CBC, sInitV, EncodingBase.Base16)
Console.WriteLine("P'=" & sOutput & " " & General.ErrorCode)

[Contents]

[HOME]   [NEXT: WIPE_File...]

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