2011-10-01 1 views
3

다음 Rijndael 코드를 사용하여 여러 번 암호화하지 않아도됩니다. 하지만 4.2GB로 ISO 파일을 암호화 할 수없는 이유는 무엇입니까? 실제로 내 컴퓨터는 16GB 메모리를 가지고 있으며 메모리 문제가되어서는 안됩니다. 나는 Windows 7 Ultimate를 사용합니다. 이 코드는 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 
+2

당신이하려고 할 때 잘못 무엇? – AakashM

+0

1GB + 암호화 된 파일을 생성 한 후 중지되었습니다. 하지만 내 소스 파일은 4GB 이상입니다. – user774411

+0

참고로 버퍼 크기를 늘려야합니다. – Magnus

답변

2

이에서 변경 시도 : 이것에

rdlen = Convert.ToInt32(rdlen + len) 

을 :

rdlen = Convert.ToInt64(rdlen + len) 
+0

그게 작동하지만 그것은 본질적으로 'rdlen = rdlen + len'과 같습니다. –

9
rdlen = Convert.ToInt32(rdlen + len) 

Int32이 음수 2,147,483,648에서 양수 2,147,483,647와 4.2GB 때문에 범위 값으로 정수를 체결 나타낼 수는 약 두 배 내가 rdlentotlen보다 더 얻을 것이다 결코 생각 때문에 자신이 끝이없는 결코 가지고 그 고리.

VB.NET 아무것도 C#을 같은 작품 (그리고 나는 그것을하지 의심) 당신은 단순히 긴 될 것입니다 변환

rdlen = rdlen + len 

에게 긴 + 지능의 결과를 제거합니다. 여기서 Long은 64 비트 부호있는 정수이고 Int는 32 비트 부호있는 정수입니다.