Encrypts or decrypts a file using a specified mode. The key and initialization vector are passed as arrays of bytes.
Public Declare Function BLF_File Lib "diCryptoSys.dll"
(ByVal strFileOut As String, ByVal strFileIn As String,
ByRef lpKey As Byte, ByVal nKeyLen As Long, ByVal bEncrypt As Boolean,
ByVal strMode As String, ByRef lpInitV As Byte) As Long
nRet = BLF_File(strFileOut, strFileIn, abKey(0), nKeyLen, bEncrypt, strMode, abInitV(0))
long __stdcall BLF_File(const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, long keyBytes, int fEncrypt, const char *szMode, const unsigned char *lpIV);
If successful, the return value is 0; otherwise it returns a non-zero error code.
Blowfish.FileEncrypt Method (String, String, Byte[], Mode, Byte[])
Blowfish.FileDecrypt Method (String, String, Byte[], Mode, Byte[])
The initialization vector
byte array lpInitV must be exactly the block size of 8 bytes long,
except for ECB mode, where it is ignored (use 0
).
The key array lpKey can be any length between 1 and 56 bytes (448 bits).
The output file szFileOut will be overwritten without warning.
If there is an error [new in version 3.3], the output file will not exist.
The input and output filepaths must not be the same.
In ECB and CBC modes, a padding string will be added or assumed according to the method outlined in Section 6.3 of
[CMS],
which is the same as the padding method in [PKCS7] and [PKCS5].
Const MY_PATH As String = "C:\Test\" Dim abKey() As Byte Dim strFileOut As String Dim strFileIn As String Dim strFileChk As String Dim nRet As Long Dim nBytes As Long ' Construct full path names to files strFileIn = MY_PATH & "hello.txt" strFileOut = MY_PATH & "hello.blf.enc.dat" strFileChk = MY_PATH & "hello.blf.chk.txt" ' Create the key as an array of bytes ' This creates an array of 8 bytes {&HFE, &HDC, ... &H10} abKey = cnvBytesFromHexStr("fedcba9876543210") nBytes = 8 ' Encrypt plaintext file to cipher ' WARNING: output file is just clobbered nRet = BLF_File(strFileOut, strFileIn, abKey(0), nBytes, ENCRYPT, "ECB", 0) Debug.Print nRet ' Output file should be a 16-byte file hello.enc ' containing the following values in hexadecimal: ' 1A A1 51 B7 7A 5A 33 5C 4E 7E DC 84 A3 86 DC 96 ' Now decrypt it nRet = BLF_File(strFileChk, strFileOut, abKey(0), nBytes, DECRYPT, "ECB", 0) Debug.Print nRet