Encrypts or decrypts an array of Bytes in one step in Electronic Codebook (EBC) mode.
@deprecated use
BLF_BytesMode
with strMode="ECB"
.
Public Declare Function BLF_Bytes Lib "diCryptoSys.dll"
(ByRef lpOutput As Byte, ByRef lpData As Byte, ByVal nDataLen As Long,
ByRef lpKey As Byte, ByVal nKeyLen As Long, ByVal bEncrypt As Boolean) As Long
nRet = BLF_Bytes(lpOutput(0), abData(0), nDataLen, abKey(0), nKeyLen, bEncrypt)
' Note the "(0)" after the byte array parameters
long __stdcall BLF_Bytes(unsigned char *lpOutput, const unsigned char *lpInput, long nBytes, const unsigned char *lpKey, long keyBytes, int fEncrypt);
If successful, the return value is 0; otherwise it returns a non-zero error code.
Blowfish.Encrypt Method (Byte[], Byte[], Mode, Byte[])
Blowfish.Decrypt Method (Byte[], Byte[], Mode, Byte[])
with mode=Mode.ECB
.
The input data lpData must be an exact multiple of 8 bytes long. If not, an error code will be returned. The key lpKey can be any length between 1 and 56 bytes (448 bits). The output array lpOutput must be at least nDataLen bytes long. lpOutput and lpData may be the same.
Dim nRet As Long Dim strInput As String Dim strKey As String Dim sCorrect As String Dim nKeyLen As Long Dim abKey() As Byte Dim lpOutput() As Byte Dim abData() As Byte Dim nDataLen As Long ' Define test vectors in hex strKey = "FEDCBA9876543210" strInput = "0123456789ABCDEF0123456789ABCDEF" sCorrect = "0ACEAB0FC6A0A28D0ACEAB0FC6A0A28D" ' Convert to byte arrays and compute lengths nKeyLen = Len(strKey) \ 2 abKey = cnvBytesFromHexStr(strKey) nDataLen = Len(strInput) \ 2 abData = cnvBytesFromHexStr(strInput) ' Dimension array for output ReDim lpOutput(nDataLen - 1) Debug.Print "KY=" & cnvHexStrFromBytes(abKey) Debug.Print "PT=" & cnvHexStrFromBytes(abData) ' Encrypt in one-off process nRet = BLF_Bytes(lpOutput(0), abData(0), nDataLen, abKey(0), nKeyLen, ENCRYPT) Debug.Print "CT=" & cnvHexStrFromBytes(lpOutput), nRet Debug.Print "OK=" & sCorrect ' Now decrypt back nRet = BLF_Bytes(abData(0), lpOutput(0), nDataLen, abKey(0), nKeyLen, DECRYPT) Debug.Print "P'=" & cnvHexStrFromBytes(abData), nRet
This should result in output as follows:
KY=FEDCBA9876543210 PT=0123456789ABCDEF0123456789ABCDEF CT=0ACEAB0FC6A0A28D0ACEAB0FC6A0A28D 0 OK=0ACEAB0FC6A0A28D0ACEAB0FC6A0A28D P'=0123456789ABCDEF0123456789ABCDEF 0