CryptoSys API examples VB6 to VB.NET

TDEA_B64Mode

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

VB6/VBA

Debug.Print "Testing TDEA_B64Mode ..."
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

' Key is 0x737C791F25EAD0E04629254352F7DC6291E5CB26917ADA32
strKey = "c3x5HyXq0OBGKSVDUvfcYpHlyyaRetoy"
' IV is 0xB36B6BFB6231084E
strIV = "s2tr+2IxCE4="
' 0x5468697320736F6D652073616D706520636F6E74656E742E0808080808080808
'  "T h i s _ s o m e _ s a m p e _ c o n t e n t ." (padding 8 x 08)
strInput = "VGhpcyBzb21lIHNhbXBlIGNvbnRlbnQuCAgICAgICAg="
sCorrect = "12/RF4+9AvhCMfXB0qL3SkFZSClk9nUkglQiPa+a+OQ="

' Set strOutput to be same length as strInput
strOutput = String(Len(strInput), " ")

Debug.Print "KY=", strKey
Debug.Print "IV=", strIV
Debug.Print "PT=", strInput
nRet = TDEA_B64Mode(strOutput, strInput, strKey, ENCRYPT, "CBC", strIV)
Debug.Print "CT=", strOutput, nRet
Debug.Print "OK=", sCorrect

strInput = strOutput
nRet = TDEA_B64Mode(strOutput, strInput, strKey, DECRYPT, "CBC", strIV)
Debug.Print "P'=", strOutput, nRet

Output

Testing TDEA_B64Mode ...
KY=   c3x5HyXq0OBGKSVDUvfcYpHlyyaRetoy
IV=   s2tr+2IxCE4=
PT=   VGhpcyBzb21lIHNhbXBlIGNvbnRlbnQuCAgICAgICAg=
CT=   12/RF4+9AvhCMfXB0qL3SkFZSClk9nUkglQiPa+a+OQ=     0 
OK=   12/RF4+9AvhCMfXB0qL3SkFZSClk9nUkglQiPa+a+OQ=
P'=   VGhpcyBzb21lIHNhbXBlIGNvbnRlbnQuCAgICAgICAg=     0 

VB.NET

Console.WriteLine("Testing TDEA_B64Mode ...")
''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
' Key is 0x737C791F25EAD0E04629254352F7DC6291E5CB26917ADA32
strKey = "c3x5HyXq0OBGKSVDUvfcYpHlyyaRetoy"
' IV is 0xB36B6BFB6231084E
strIV = "s2tr+2IxCE4="
' 0x5468697320736F6D652073616D706520636F6E74656E742E0808080808080808
'  "T h i s _ s o m e _ s a m p e _ c o n t e n t ." (padding 8 x 08)
strInput = "VGhpcyBzb21lIHNhbXBlIGNvbnRlbnQuCAgICAgICAg="
sCorrect = "12/RF4+9AvhCMfXB0qL3SkFZSClk9nUkglQiPa+a+OQ="
' Set strOutput to be same length as strInput
''strOutput = String(Len(strInput), " ")
Console.WriteLine("KY=" & " " & strKey)
Console.WriteLine("IV=" & " " & strIV)
Console.WriteLine("PT=" & " " & strInput)
strOutput = Tdea.Encrypt(strInput, strKey, Mode.CBC, strIV, EncodingBase.Base64)
Console.WriteLine("CT=" & " " & strOutput)
Console.WriteLine("OK=" & " " & sCorrect)
strInput = strOutput
strOutput = Tdea.Decrypt(strInput, strKey, Mode.CBC, strIV, EncodingBase.Base64)
Console.WriteLine("P'=" & " " & strOutput)

[Contents]

[HOME]   [NEXT: TDEA_Bytes...]

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