Encrypts or decrypts a file using a specified mode. The key and initialization vector are passed as hexadecimal strings.
Public Declare Function TDEA_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 = TDEA_FileHex(strFileOut, strFileIn, strHexKey, bEncrypt, strMode, strHexIV)
String with the full path name of the output
file to be created.String with the full path name of the input file
to be processed.String containing the key in hexadecimal.Boolean direction flag:
set as True to encrypt or False
to decrypt.String specifying the confidentiality mode:String containing the initialization vector (IV)
in hexadecimal.
long _stdcall TDEA_FileHex(const char *lpszFileOut, const char *lpszFileIn,
const char *lpszKey, int bEncrypt,
const char *lpszMode, const char *lpszIV);
Long: If successful, the return value is 0;
otherwise it returns a non-zero error code.
Tdea.FileEncrypt Method (String, String, String, Mode, String)
Tdea.FileDecrypt Method (String, String, String, Mode, String)
The key string strHexKey must be exactly 48 hex characters long (i.e. representing exactly 24 bytes/192 bits).
The initialization vector strHexIV
must be exactly 16 hex characters long
(i.e. representing exactly the block size of 8 bytes), except for ECB mode, where it is ignored (use "").
Valid hexadecimal characters are [0-9A-Fa-f].
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].
Note that even though the parameters are in hexadecimal-encoded form, the encrypted file is still binary.
This example will encrypt the file "bigfile.dat" in CBC mode using the key
0xfedcba9876543210fedcba9876543210fedcba9876543210 and initialization vector
0x0123456789abcdef. The output file "bigfile.cbc" will be created or
overwritten. It then decrypts the ciphertext file as a check, creating or
overwriting the file "bigfile.chk".
Dim nRet As Long
nRet = TDEA_FileHex("bigfile.cbc", "bigfile.dat", _
"fedcba9876543210fedcba9876543210fedcba9876543210", _
ENCRYPT, "CBC", "0123456789abcdef")
Debug.Print nRet
' and decrypt it as a check
nRet = TDEA_FileHex("bigfile.chk", "bigfile.cbc", _
"fedcba9876543210fedcba9876543210fedcba9876543210", _
DECRYPT, "CBC", "0123456789abcdef")
Debug.Print nRet