CryptoSys API Library Manual

TDEA_FileExt

Encrypts or decrypts a file using a specified mode with extended options.

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

VBA/VB6 Syntax

Public Declare Function TDEA_FileExt 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, ByVal nOptions As Long) As Long

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

C/C++ Syntax

long __stdcall TDEA_FileExt(const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, int fEncrypt, const char *szMode, const unsigned char *lpIV, long nOptions);

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 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.
nOptions
[in] option flags:
Zero (0) for default behaviour as per TDEA_File.
API_IV_PREFIX to prepend the IV before the ciphertext in the output file (ignored for ECB mode)
API_PAD_LEAVE to leave any padding in place when decrypting (ECB and CBC modes only; ignored if encrypting)

Returns (VBA/C)

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

.NET Equivalent

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

Remarks

For the default behaviour, see TDEA_File. The options are ignored if not applicable. For more information on the behaviour of the options, see Extensions to block cipher functions for files.

Example

Dim abKey() As Byte
Dim abIV() As Byte
Dim strFilePlain As String
Dim strFileCipher As String
Dim strFileCheck As String
Dim strFileChk1 As String
Dim nRet As Long

' Input file is exactly 19 bytes long
strFilePlain = "nowis19.txt"
strFileCipher = "nowis19.tdea.enc.dat"
strFileCheck = "nowis19.tdea.chk.txt"
strFileChk1 = "nowis19.tdea.chk1.txt"

' Create the key and IV as arrays of bytes
' This creates an array of 24 bytes {&H01, &H23, ... &H67}
abKey = cnvBytesFromHexStr("0123456789ABCDEFFEDCBA987654321089ABCDEF01234567")
' This creates an array of 8 bytes {&H12, &H34, ... &HEF}
abIV = cnvBytesFromHexStr("1234567890ABCDEF ")

' Encrypt plaintext file to ciphertext with embedded IV at beginning
' Output file = 32-byte ciphertext file .enc.dat
nRet = TDEA_FileExt(strFileCipher, strFilePlain, abKey(0), ENCRYPT, "CBC", abIV(0), API_IV_PREFIX)
Debug.Print "TDEA_FileExt(ENCRYPT) returns " & nRet
Debug.Print "Output file '" & strFileCipher & "' is " & FileLen(strFileCipher) & " bytes"

' Now decrypt it back to original plaintext - this file should be 19 bytes long
nRet = TDEA_FileExt(strFileCheck, strFileCipher, abKey(0), DECRYPT, "CBC", abIV(0), API_IV_PREFIX)
Debug.Print "TDEA_FileExt(DECRYPT) returns " & nRet
Debug.Print "Output file '" & strFileCheck & "' is " & FileLen(strFileCheck) & " bytes"

' Alternatively, decrypt and leave padding bytes in place - this file should be 24 bytes long
nRet = TDEA_FileExt(strFileChk1, strFileCipher, abKey(0), DECRYPT, "CBC", abIV(0), API_IV_PREFIX + API_PAD_LEAVE)
Debug.Print "TDEA_FileExt(DECRYPT, API_PAD_LEAVE) returns " & nRet
Debug.Print "Output file '" & strFileChk1 & "' is " & FileLen(strFileChk1) & " bytes"

This should give the following output

TDEA_FileExt(ENCRYPT) returns 0
Output file 'nowis19.tdea.enc.dat' is 32 bytes
TDEA_FileExt(DECRYPT) returns 0
Output file 'nowis19.tdea.chk.txt' is 19 bytes
TDEA_FileExt(DECRYPT, API_PAD_LEAVE) returns 0
Output file 'nowis19.tdea.chk1.txt' is 24 bytes

See Also

TDEA_File

[Contents] [Index]

[PREV: TDEA_File...]   [Contents]   [Index]   
   [NEXT: TDEA_FileHex...]

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