CryptoSys API Library Manual

BLF_File

Encrypts or decrypts a file using a specified mode. The key and initialization vector are passed as arrays of bytes.

VBA/VB6 Syntax

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))

C/C++ Syntax

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);

Parameters

szFileOut
[in] with the full path name of the output file to be created.
szFileIn
[in] with the full path name of the input file to be processed.
lpKey
[in] array containing the key.
keyBytes
[in] containing the length of the key in bytes.
fEncrypt
[in] direction flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
szMode
[in] 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.
lpIV
[in] array containing the initialization vector (IV), or zero (0) for ECB mode.

Returns (VBA/C)

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

.NET Equivalent

Blowfish.FileEncrypt Method (String, String, Byte[], Mode, Byte[])
Blowfish.FileDecrypt Method (String, String, Byte[], Mode, Byte[])

Remarks

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].

Example

    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

See Also

BLF_FileExt BLF_FileHex

[Contents] [Index]

[PREV: BLF_BytesMode...]   [Contents]   [Index]   
   [NEXT: BLF_FileExt...]

Copyright © 2001-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-01-07T07:42:00Z.