CryptoSys API examples VB6 to VB.NET

BLF_B64Mode

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

VB6/VBA

Debug.Print "Testing BLF_B64Mode ..."
Dim nRet As Long
Dim strOutput As String
Dim strInput As String
Dim strKey As String
Dim strIV As String
Dim sCorrect As String

' "7654321 Now is the time for " padded to 32 bytes with 4 nulls
strInput = "NzY1NDMyMSBOb3cgaXMgdGhlIHRpbWUgZm9yIAAAAAA="
sCorrect = "a3e01jAG3uYFsVbidAOXk1jeuecVRhbZWfFlK9X/ksw="
' Key is 0x0123456789ABCDEFF0E1D2C3B4A59687
strKey = "ASNFZ4mrze/w4dLDtKWWhw=="
' IV is 0xFEDCBA9876543210
strIV = "/ty6mHZUMhA="
' Set strOutput to be same length as strInput
strOutput = String(Len(strInput), " ")

Debug.Print "KY=", strKey
Debug.Print "IV=", strIV
Debug.Print "PT=", strInput
' Encrypt in one-off process
nRet = BLF_B64Mode(strOutput, strInput, strKey, ENCRYPT, "CBC", strIV)
Debug.Print "CT=", strOutput, nRet
Debug.Print "OK=", sCorrect

' Now decrypt back to plain text
strInput = strOutput
nRet = BLF_B64Mode(strOutput, strInput, strKey, DECRYPT, "CBC", strIV)
Debug.Print "P'=", strOutput, nRet

Output

Testing BLF_B64Mode ...
KY=   ASNFZ4mrze/w4dLDtKWWhw==
IV=   /ty6mHZUMhA=
PT=   NzY1NDMyMSBOb3cgaXMgdGhlIHRpbWUgZm9yIAAAAAA=
CT=   a3e01jAG3uYFsVbidAOXk1jeuecVRhbZWfFlK9X/ksw=     0 
OK=   a3e01jAG3uYFsVbidAOXk1jeuecVRhbZWfFlK9X/ksw=
P'=   NzY1NDMyMSBOb3cgaXMgdGhlIHRpbWUgZm9yIAAAAAA=     0 

VB.NET

Console.WriteLine("Testing BLF_B64Mode ...")
Dim nRet As Integer
Dim strOutput As String
Dim strInput As String
Dim strKey As String
Dim strIV As String
Dim sCorrect As String

' "7654321 Now is the time for " padded to 32 bytes with 4 nulls
strInput = "NzY1NDMyMSBOb3cgaXMgdGhlIHRpbWUgZm9yIAAAAAA="
sCorrect = "a3e01jAG3uYFsVbidAOXk1jeuecVRhbZWfFlK9X/ksw="
' Key is 0x0123456789ABCDEFF0E1D2C3B4A59687
strKey = "ASNFZ4mrze/w4dLDtKWWhw=="
' IV is 0xFEDCBA9876543210
strIV = "/ty6mHZUMhA="
' Set strOutput to be same length as strInput
''strOutput = String(Len(strInput), " ")

Console.WriteLine("KY=" & " " & strKey)
Console.WriteLine("IV=" & " " & strIV)
Console.WriteLine("PT=" & " " & strInput)
' Encrypt in one-off process
strOutput = Blowfish.Encrypt(strInput, strKey, Mode.CBC, strIV, EncodingBase.Base64)
Console.WriteLine("CT=" & " " & strOutput & " " & nRet)
Console.WriteLine("OK=" & " " & sCorrect)

' Now decrypt back to plain text
strInput = strOutput
strOutput = Blowfish.Decrypt(strInput, strKey, Mode.CBC, strIV, EncodingBase.Base64)
Console.WriteLine("P'=" & " " & strOutput & " " & nRet)

[Contents]

[HOME]   [NEXT: BLF_Bytes...]

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