Encrypts or decrypts data represented as a hexadecimal string using a specified mode.
VB6/VBA
Debug.Print "Testing BLF_HexMode ..." Dim nRet As Long Dim strOutput As String Dim strInput As String Dim strHexKey As String Dim strHexIV As String Dim sCorrect As String ' "7654321 Now is the time for " padded to 32 bytes with 4 nulls strInput = "37363534333231204E6F77206973207468652074696D6520666F722000000000" sCorrect = "6B77B4D63006DEE605B156E27403979358DEB9E7154616D959F1652BD5FF92CC" strHexKey = "0123456789ABCDEFF0E1D2C3B4A59687" strHexIV = "FEDCBA9876543210" ' Set strOutput to be same length as strInput strOutput = String(Len(strInput), " ") Debug.Print "KY=", strHexKey Debug.Print "IV=", strHexIV Debug.Print "PT=", strInput ' Encrypt in one-off process nRet = BLF_HexMode(strOutput, strInput, strHexKey, ENCRYPT, "CBC", strHexIV) Debug.Print "CT=", strOutput, nRet Debug.Print "OK=", sCorrect ' Now decrypt back to plain text strInput = strOutput nRet = BLF_HexMode(strOutput, strInput, strHexKey, DECRYPT, "CBC", strHexIV) Debug.Print "P'=", strOutput, nRet
Output
Testing BLF_HexMode ... KY= 0123456789ABCDEFF0E1D2C3B4A59687 IV= FEDCBA9876543210 PT= 37363534333231204E6F77206973207468652074696D6520666F722000000000 CT= 6B77B4D63006DEE605B156E27403979358DEB9E7154616D959F1652BD5FF92CC 0 OK= 6B77B4D63006DEE605B156E27403979358DEB9E7154616D959F1652BD5FF92CC P'= 37363534333231204E6F77206973207468652074696D6520666F722000000000 0
VB.NET
Console.WriteLine("Testing BLF_HexMode ...") ''Dim nRet As Integer Dim strOutput As String Dim strInput As String Dim strHexKey As String Dim strHexIV As String Dim sCorrect As String ' "7654321 Now is the time for " padded to 32 bytes with 4 nulls strInput = "37363534333231204E6F77206973207468652074696D6520666F722000000000" sCorrect = "6B77B4D63006DEE605B156E27403979358DEB9E7154616D959F1652BD5FF92CC" strHexKey = "0123456789ABCDEFF0E1D2C3B4A59687" strHexIV = "FEDCBA9876543210" ' Set strOutput to be same length as strInput ''strOutput = String(Len(strInput), " ") Console.WriteLine("KY=" & " " & strHexKey) Console.WriteLine("IV=" & " " & strHexIV) Console.WriteLine("PT=" & " " & strInput) ' Encrypt in one-off process strOutput = Blowfish.Encrypt(strInput, strHexKey, Mode.CBC, strHexIV) Console.WriteLine("CT=" & " " & strOutput) Console.WriteLine("OK=" & " " & sCorrect) ' Now decrypt back to plain text strInput = strOutput strOutput = Blowfish.Decrypt(strInput, strHexKey, Mode.CBC, strHexIV) Console.WriteLine("P'=" & " " & strOutput)
[Contents]