Use FileStream
to read in chunks of 4096 bytes then encrypt them (or do any necessary processing) and then write them to the new file stream, since it's streaming in/out it won't hog up all the memory trying to read/write everything at once, simple example:
Dim bytesRead As Integer
Dim buffer(4096) As Byte 'Default buffer size is 4096
Using inFile As New IO.FileStream("C:\\Temp\\inFile.bin", FileMode.Open)
Using outFile As New IO.FileStream("C:\\Temp\\outFile.bin", FileMode.Append, FileAccess.Write)
Do
bytesRead = inFile.Read(buffer, 0, buffer.Length)
If bytesRead > 0 Then
' Do encryption or any necessary processing of the bytes
outFile.Write(buffer, 0, bytesRead)
End If
Loop While bytesRead > 0
End Using
End Using