CryptoSys API Library Manual

AES256_File

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

@deprecated use CIPHER_FileEncrypt() and CIPHER_FileDecrypt() instead.

VBA/VB6 Syntax

Public Declare Function AES256_File Lib "diCryptoSys.dll" (ByVal strFileOut As String, ByVal strFileIn As String, ByRef lpKey As Byte, ByVal bEncrypt As Boolean, ByVal strMode As String, ByRef lpInitV As Byte) As Long

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

C/C++ Syntax

long __stdcall AES256_File(const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, 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.
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 128-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

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

Remarks

The key array abKey() must be exactly 32 bytes long (i.e. 256 bits). The initialization vector abInitV() must be exactly the block size of 16 bytes long, except for ECB mode, where it is ignored (use 0). 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

This example will encrypt the file "now.txt" in ECB mode using the 256-bit key 0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f, and then decrypt back to the plain text file "aesnow.chk" as a check. Both output files "aesnow.enc" and "aesnow.chk" will be created or overwritten.

    Const MY_PATH As String = "C:\Test\"
    Dim strFileOut As String, strFileIn As String, strFileChk As String
    Dim nRet As Long
    Dim abKey() As Byte

    ' Construct full path names to files
    strFileIn = MY_PATH & "now.txt"
    strFileOut = MY_PATH & "now.aes256.enc.dat"
    strFileChk = MY_PATH & "now.aes256.chk.txt"

    ' Convert key to byte array
    abKey = _
cnvBytesFromHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f")
    ' Encrypt plaintext file to cipher
    nRet = AES256_File(strFileOut, strFileIn, abKey(0), ENCRYPT, "ECB", 0)
    If nRet <> 0 Then
        Debug.Print "Error " & nRet & ": " & apiErrorLookup(nRet)
    End If

    ' Now decrypt it
    nRet = AES256_File(strFileChk, strFileOut, abKey(0), DECRYPT, "ECB", 0)
    If nRet <> 0 Then
        Debug.Print "Error " & nRet & ": " & apiErrorLookup(nRet)
    End If

See Also

AES256_FileExt AES256_FileHex

[Contents] [Index]

[PREV: AES256_BytesMode...]   [Contents]   [Index]   
   [NEXT: AES256_FileExt...]

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