CryptoSys API Library Manual

BLF_HexMode

Encrypts or decrypts data represented as a hexadecimal string using a specified mode. The key and initialization vector are represented as a hexadecimal string.

VB6/VBA Syntax

Public Declare Function BLF_HexMode Lib "diCryptoSys.dll" (ByVal strOutput As String, ByVal strInput As String, ByVal strHexKey As String, ByVal bEncrypt As Boolean, ByVal strMode As String, ByVal strHexIV As String) As Long

nRet = BLF_HexMode(strOutput, strInput, strHexKey, bEncrypt, strMode, strHexIV)

Parameters

strOutput
[out] String of sufficient length to receive the output.
strInput
[in] String containing the input data in hexadecimal.
strHexKey
[in] String containing the key in hexadecimal.
bEncrypt
[in] Boolean direction flag: set as True to encrypt or False to decrypt.
strMode
[in] String specifying the confidentiality mode:
"ECB" for Electronic Codebook mode,
"CBC" for Cipher Block Chaining mode,
"CFB" for 64-bit Cipher Feedback mode,
"OFB" for Output Feedback mode, or
"CTR" for Counter mode.
strHexIV
[in] String containing the initialization vector (IV) in hexadecimal.

C/C++ Syntax

long _stdcall BLF_HexMode(char *strOutput, const char *strInput, const char *strHexKey, int bEncrypt, const char *strMode, const char *strHexIV);

Returns (VB6/C)

Long: If successful, the return value is 0; otherwise it returns a non-zero error code.

.NET Equivalent

Blowfish.Encrypt Method (String, String, Mode, String)
Blowfish.Decrypt Method (String, String, Mode, String)

COM/ASP Equivalent

blf.HexMode
Public Function HexMode(ByVal strInput As String, ByVal strHexKey As String, ByVal bEncrypt As Boolean, ByVal strMode As String, ByVal strHexIV As String) As String

See blf.HexMode.

Remarks

The length of the input string strInput must be a multiple of 16 hex characters long (i.e. representing a multiple of 8 bytes). If not, an error code will be returned.. The initialization vector string strIV must be exactly 16 hex characters long (i.e. representing exactly 8 bytes) unless strMode is ECB, in which case strIV is ignored (use ""). The key strKey can be any even length between 2 and 112 hexadecimal characters. Valid hexadecimal characters are [0-9A-Fa-f]. The output string strOutput must be set up with at least the same number of characters as the input string before calling. The variables strOutput and strInput should be different.

Example

    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

This should result in output as follows:

KY=0123456789ABCDEFF0E1D2C3B4A59687
IV=FEDCBA9876543210
PT=37363534333231204E6F77206973207468652074696D6520666F722000000000
CT=6B77B4D63006DEE605B156E27403979358DEB9E7154616D959F1652BD5FF92CC    0
OK=6B77B4D63006DEE605B156E27403979358DEB9E7154616D959F1652BD5FF92CC
P'=37363534333231204E6F77206973207468652074696D6520666F722000000000    0

See Also

BLF_Hex

[Contents] [Index]

[HOME]   [NEXT: BLF_Init...]

Copyright © 2001-11 D.I. Management Services Pty Ltd. All rights reserved.