Encrypts or decrypts a file using a specified mode with extended options.
@deprecated use CIPHER_FileEncrypt() and CIPHER_FileDecrypt() instead.
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)
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);
TDEA_File
.If successful, the return value is 0; otherwise it returns a non-zero error code.
Tdea.FileEncrypt Method (String, String, Byte[], Mode, Byte[], CipherFileOption)
Tdea.FileDecrypt Method (String, String, Byte[], Mode, Byte[], CipherFileOption)
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.
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