Carries out the Blowfish transformation function on a byte array
according to the direction
and mode set up by an earlier call to BLF_Init()
or BLF_InitHex()
.
Public Declare Function BLF_Update Lib "diCryptoSys.dll"
(ByVal hContext As Long, ByRef lpData As Byte, ByVal nDataLen As Long) As Long
nRet = BLF_Update(hContext, abData(0), nDataLen)
long __stdcall BLF_Update(long hContext, unsigned char *lpData, long nDataLen);
BLF_Init()
or BLF_InitHex()
.If successful, the return value is 0; otherwise it returns a non-zero error code.
Blowfish.Update Method (Byte[])
lpData must be an exact multiple of 8 bytes long. If not, an error code will be returned. Note that the output overwrites the input.
' Contrived example to encrypt sample blocks in CBC mode Dim abBlock(7) As Byte Dim abKey() As Byte Dim nKeyLen As Long Dim abInitV() As Byte Dim hContext As Long Dim nRet As Long Dim i As Integer Dim j As Integer ' Specify a key and its length abKey = cnvBytesFromHexStr("FEDCBA9876543210") nKeyLen = UBound(abKey) - LBound(abKey) + 1 ' And an IV (length is assumed to be 8 bytes) abInitV = cnvBytesFromHexStr("0123456789abcdef") ' Initialise the context hContext = BLF_Init(abKey(0), nKeyLen, ENCRYPT, "CBC", abInitV(0)) If hContext = 0 Then nRet = BLF_InitError() Debug.Print "BFL_Init Failed: " & apiErrorLookup(nRet) Exit Function End If Debug.Print "KY=" & cnvHexStrFromBytes(abKey) Debug.Print "IV=" & cnvHexStrFromBytes(abInitV) ' Create some test blocks and encrypt them For i = 1 To 4 For j = 0 To 7 abBlock(j) = CByte(i) Next Debug.Print "PT(" & i & ")=" & cnvHexStrFromBytes(abBlock) nRet = BLF_Update(hContext, abBlock(0), 8) Debug.Print "CT(" & i & ")=" & cnvHexStrFromBytes(abBlock) Next ' Clear the context BLF_Final (hContext)
This should result in output as follows:
KY=FEDCBA9876543210 IV=0123456789ABCDEF PT(1)=0101010101010101 CT(1)=46733BCD9C72C5E3 PT(2)=0202020202020202 CT(2)=F434DA62B6869A06 PT(3)=0303030303030303 CT(3)=2AE6DFE458559138 PT(4)=0404040404040404 CT(4)=DEEBF97D6F83A5F3
BLF_Init
BLF_InitHex
BLF_UpdateHex
BLF_Final