[VB6 equivalent: CIPHER_File]
Const MY_PATH As String = "" Dim abKey() As Byte Dim abIV() As Byte Dim strFileEnc As String Dim strFileIn As String Dim strFileChk As String Dim nRet As Integer ' Construct full path names to files strFileIn = MY_PATH & "hello.txt" strFileEnc = MY_PATH & "hello.aes128.enc.dat" strFileChk = MY_PATH & "hello.aes128.chk.txt" ' Create the key as an array of bytes ' This creates an array of 16 bytes {&HFE, &HDC, ... &H10} abKey = Cnv.FromHex("fedcba9876543210fedcba9876543210") ' Create the IV at random abIV = Rng.Bytes(Tdea.BlockSize) ' Display the IV (this needs to be communicated separately to the recipient) Console.WriteLine("IV=" & Cnv.ToHex(abIV)) ' Encrypt plaintext file to ciphertext using AES-128 in counter (CTR) mode ' (This will create a file of exactly the same size as the input) nRet = Cipher.FileEncrypt(strFileEnc, strFileIn, abKey, abIV, CipherAlgorithm.Aes128, Mode.CTR) Console.WriteLine("CIPHER_File(ENCRYPT) returns " & nRet) ' Now decrypt it nRet = Cipher.FileDecrypt(strFileChk, strFileEnc, abKey, abIV, CipherAlgorithm.Aes128, Mode.CTR) Console.WriteLine("CIPHER_File(DECRYPT) returns " & nRet)
See Also:
Cipher.FileDecrypt Method
Cipher.FileEncrypt Method