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.

VB6/VBA Syntax

Public Declare Function BLF_File Lib "diCryptoSys.dll" (ByVal strFileOut As String, ByVal strFileIn As String, ByRef abKey As Byte, ByVal nKeyLen As Long, ByVal bEncrypt As Boolean, ByVal strMode As String, ByRef abInitV As Byte) As Long

nRet = BLF_File(strFileOut, strFileIn, abKey(0), nKeyLen, bEncrypt, strMode, abInitV(0))

Parameters

strFileOut
[in] String with the full path name of the output file to be created.
strFileIn
[in] String with the full path name of the input file to be processed.
abKey
[in] Byte array containing the key.
nKeyLen
[in] Long containing the length of the key in bytes.
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.
abInitV
[in] Byte array containing the initialization vector (IV), or zero (0) for ECB mode.

C/C++ Syntax

long _stdcall BLF_File(const char *strFileOut, const char *strFileIn, const unsigned char *key, long keyBytes, int bEncrypt, const char *strMode, const unsigned char *iv);

Returns (VB6/C)

Long: 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 abInitV must be exactly the block size of 8 bytes long, except for ECB mode, where it is ignored (use 0). The key array abKey can be any length between 1 and 56 bytes (448 bits). The output file strFileOut 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]

[HOME]   [NEXT: BLF_FileExt...]

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