我使用以下Rijndael代碼多次進行加密而不失敗。但爲什麼它不能用4.2 GB加密ISO文件?事實上,我的電腦有16GB內存,它不應該是一個內存問題。我使用Windows 7旗艦版。代碼使用Visual Studio 2010(一個VB.NET項目)編譯爲winform(.Net 4)。爲什麼Rijndael加密代碼不適用於大文件?
我已檢查ISO文件是否可以掛載爲虛擬驅動器,甚至可以刻錄到DVD光盤。所以這不是ISO文件問題。
我的問題:爲什麼下面的代碼不能加密大小爲4.2GB的ISO文件?這是由Windows/.NET 4實施的限制造成的嗎?
Private Sub DecryptData(inName As String, outName As String, rijnKey() As Byte, rijnIV() As Byte)
'Create the file streams to handle the input and output files.
Dim fin As New IO.FileStream(inName, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim fout As New IO.FileStream(outName, System.IO.FileMode.OpenOrCreate,
System.IO.FileAccess.Write)
fout.SetLength(0)
'Create variables to help with read and write.
Dim bin(100) As Byte 'This is intermediate storage for the encryption.
Dim rdlen As Long = 0 'This is the total number of bytes written.
Dim totlen As Long = fin.Length 'Total length of the input file.
Dim len As Integer 'This is the number of bytes to be written at a time.
'Creates the default implementation, which is RijndaelManaged.
Dim rijn As New Security.Cryptography.RijndaelManaged
Dim encStream As New Security.Cryptography.CryptoStream(fout,
rijn.CreateDecryptor(rijnKey, rijnIV), Security.Cryptography.CryptoStreamMode.Write)
'Read from the input file, then encrypt and write to the output file.
While rdlen < totlen
len = fin.Read(bin, 0, 100)
encStream.Write(bin, 0, len)
rdlen = Convert.ToInt32(rdlen + len)
End While
encStream.Close()
fout.Close()
fin.Close()
End Sub
當您嘗試錯在何處? – AakashM
產生1GB ++加密文件後停止。但是我的源文件大於4GB – user774411
在附註中,您應該增加緩衝區大小。 – Magnus