
i tested this on windows xp/7/10 64bit and worked good with huge files.
i changed some part with this :
Code:
Private Sub EncryptFile(sSrcFile As String, sDestFile As String, baKey() As Byte)
' fixed error about main files size smaller than chunk difination
Dim CHUNK_SIZE As Long
Dim pInput As stdole.IUnknown
Dim pOutput As stdole.IUnknown
Dim baChunk() As Byte
Dim dblTimer As Double
Dim lSize As Currency
Dim Chunkreaded As Currency
dblTimer = Timer
AesChunkedInit baKey
Set pInput = StreamOpenFile(sSrcFile)
Set pOutput = StreamOpenFile(sDestFile, AlwaysCreate:=True)
lSize = StreamGetSize(pInput)
' if size of file smaller than chunksize
If lSize < (1024@ * 1024 * 2) Then CHUNK_SIZE = lSize Else CHUNK_SIZE = 1024@ * 1024 * 2 ' x mb
Chunkreaded = 31 ' extra byte
p.Value = 0
p.Caption1 = p.Value & " %"
p.Caption2 = ""
Do
DoEvents
baChunk = StreamReadBytes(pInput, CHUNK_SIZE)
If UBound(baChunk) < 0 Then
Exit Do
End If
Chunkreaded = Chunkreaded + UBound(baChunk) + 1 ' +1 added because of UBound
' progress
p.Caption2 = lSize & " / " & Chunkreaded
If CHUNK_SIZE = lSize Then
' progress
p.Value = 100
p.Caption1 = p.Value & " %"
Else
' progress
p.Value = Fix(CCur((Chunkreaded * 100) / lSize))
p.Caption1 = p.Value & " %"
End If
DoEvents
AesChunkedEncryptArray baChunk, baChunk, Final:=StreamEOF(pInput)
StreamWriteBytes pOutput, baChunk
Loop
' progress
p.Caption2 = lSize & " / Elapsed " & Format$(Timer - dblTimer, "0.000")
p.Value = 100
p.Caption1 = p.Value & " %"
End Sub
Private Sub DecryptFile(sSrcFile As String, sDestFile As String, baKey() As Byte)
' fixed error about main files size smaller than chunk difination
Dim CHUNK_SIZE As Long
Dim pInput As stdole.IUnknown
Dim pOutput As stdole.IUnknown
Dim baChunk() As Byte
Dim dblTimer As Double
Dim lSize As Currency
Dim Chunkreaded As Currency
dblTimer = Timer
AesChunkedInit baKey
Set pInput = StreamOpenFile(sSrcFile)
Set pOutput = StreamOpenFile(sDestFile, True)
lSize = StreamGetSize(pInput)
' if size of file smaller than chunksize
If lSize < (1024@ * 1024 * 2) Then CHUNK_SIZE = lSize Else CHUNK_SIZE = 1024@ * 1024 * 2 ' x mb
Chunkreaded = 0 ' extra byte
' progress
p.Value = 0
p.Caption1 = p.Value & " %"
Do
baChunk = StreamReadBytes(pInput, CHUNK_SIZE)
If UBound(baChunk) < 0 Then
Exit Do
End If
Chunkreaded = Chunkreaded + UBound(baChunk) + 1 ' +1 added because of UBound
' progress
p.Caption2 = lSize & " / " & Chunkreaded
If CHUNK_SIZE = lSize Then
' progress
p.Value = 100
p.Caption1 = p.Value & " %"
Else
' progress
p.Value = Fix(CCur((Chunkreaded * 100) / lSize))
p.Caption1 = p.Value & " %"
End If
DoEvents
AesChunkedDecryptArray baChunk, baChunk, Final:=StreamEOF(pInput)
StreamWriteBytes pOutput, baChunk
Loop
' progress
p.Caption2 = lSize & " / Elapsed " & Format$(Timer - dblTimer, "0.000")
p.Value = 100
p.Caption1 = p.Value & " %"
End Sub
i attached test program :
test.zip
1-Before asking the question in #15, I had converted all the debugs to caption=xxx or label.caption=xxx and then asked the question, but I solved the problem by setting the timer control, but still my question 1 remains in #15 and is about memory and slow occupation. The speed of the computer is working at high volumes. Can the memory be optimized here like the previous HugeBinaryFile class (autoflush method)?
2-I sent the code I added and changed above so solved that question.
3- The number of videos is not known, but the size of each file can be estimated up to 300 to 400 MB, and the number of files may reach 10. But if we consider the number of files less than 4 GB, what is the solution?
Yes, I know about editing running code, and I've talked enough about it before in the threads I created.
I do not work for a specific person and the company has many people, I have done this before with less features and work with separate files, but this time it is different, the files must be inside the executable file.
I'm still looking for question 3 on how to play this file without having to save it to disk.
For example, if I have an encrypted file with a size of 300 or 400 MB, but I want to decrypt it and play it without having to write it to disk, what should I do?
My two issues
1- How to decrypt without saving to disk
2- Play formats such as mp4 or mkv in the program.