CryptoSys API Library Manual

AES256_FileHex

Encrypts or decrypts a file using a specified mode. The key and initialization vector are passed as hexadecimal strings.

VBA/VB6 Syntax

Public Declare Function AES256_FileHex Lib "diCryptoSys.dll" (ByVal strFileOut As String, ByVal strFileIn As String, ByVal strHexKey As String, ByVal bEncrypt As Boolean, ByVal strMode As String, ByVal strHexIV As String) As Long

nRet = AES256_FileHex(strFileOut, strFileIn, strHexKey, bEncrypt, strMode, strHexIV)

C/C++ Syntax

long __stdcall AES256_FileHex(const char *szFileOut, const char *szFileIn, const char *szKey, int fEncrypt, const char *szMode, const char *szIV);

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.
szKey
[in] containing the key in hexadecimal.
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.
szIV
[in] containing the initialization vector (IV) in hexadecimal.

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, String, Mode, String)
Aes256.FileDecrypt Method (String, String, String, Mode, String)

Remarks

The key string szHexKey must be exactly 64 hexadecimal characters long (i.e. representing exactly 32 bytes/256 bits). The initialization vector szHexIV must be exactly 32 hexadecimal characters long (i.e. representing exactly the block size of 16 bytes), except for ECB mode, where it is ignored (use ""). 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].

Note that even though the parameters are in hexadecimal-encoded form, the encrypted file is still binary.

Example

This example will encrypt the file "bigfile.dat" in CBC mode using the 256-bit key 0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f and initialization vector 0x0123456789abcdef0123456789abcdef. The output file "bigfile.cbc" will be created or overwritten.

Dim nRet As Long
nRet = AES256_FileHex("bigfile.cbc", "bigfile.dat", _
    "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", _
    ENCRYPT, "CBC", "0123456789abcdef0123456789abcdef")
If nRet <> 0 Then
    Debug.Print "AES256_FileHex failed: " & apiErrorLookup(nRet)
Else
    Debug.Print "AES256_FileHex encrypted file OK"
End If

See Also

AES256_File

[Contents] [Index]

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

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