[VB6 equivalent: TDEA_FileExt]
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 Integer ' 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 = Cnv.FromHex("0123456789ABCDEFFEDCBA987654321089ABCDEF01234567") ' This creates an array of 8 bytes {&H12, &H34, ... &HEF} abIV = Cnv.FromHex("1234567890ABCDEF ") ' Encrypt plaintext file to ciphertext with embedded IV at beginning ' Output file = 32-byte ciphertext file .enc.dat nRet = Tdea.FileEncrypt(strFileCipher, strFilePlain, abKey, Mode.CBC, abIV, CipherFileOption.PrefixIV) Console.WriteLine("TDEA_FileExt(ENCRYPT) returns " & nRet) Console.WriteLine("Output file '" & strFileCipher & "' is " & FileLen(strFileCipher) & " bytes") ' Now decrypt it back to original plaintext - this file should be 19 bytes long nRet = Tdea.FileDecrypt(strFileCheck, strFileCipher, abKey, Mode.CBC, abIV, CipherFileOption.PrefixIV) Console.WriteLine("TDEA_FileExt(DECRYPT) returns " & nRet) Console.WriteLine("Output file '" & strFileCheck & "' is " & FileLen(strFileCheck) & " bytes") ' Alternatively, decrypt and leave padding bytes in place - this file should be 24 bytes long nRet = Tdea.FileDecrypt(strFileChk1, strFileCipher, abKey, Mode.CBC, abIV, CipherFileOption.PrefixIV Or CipherFileOption.LeavePadding) Console.WriteLine("TDEA_FileExt(DECRYPT, General.PAD_LEAVE) returns " & nRet) Console.WriteLine("Output file '" & strFileChk1 & "' is " & FileLen(strFileChk1) & " bytes")
See Also:
Tdea.FileDecrypt Method (String, String, Byte[], Mode, Byte[], CipherFileOption)
Tdea.FileEncrypt Method (String, String, Byte[], Mode, Byte[], CipherFileOption)