3

以下の Rijndael コードを使用して、何度も確実に暗号化を行っています。しかし、4.2 GB の ISO ファイルを暗号化できないのはなぜですか? 実際、私のコンピュータには 16GB のメモリが搭載されており、メモリの問題ではないはずです。Windows 7 Ultimate を使用しています。コードは、Visual Studio 2010 (VB.NET プロジェクト) を使用して winform (.Net 4) としてコンパイルされます。

ISO ファイルに問題がなく、仮想ドライブとしてマウントでき、DVD ROM に書き込むこともできることを確認しました。したがって、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
4

2 に答える 2

9
rdlen = Convert.ToInt32(rdlen + len)

Int32は、負の 2,147,483,648 から正の 2,147,483,647 までの範囲の値を持つ符号付き整数を表すことができます。4.2GB は約 2 倍であるため、これrdlenよりも大きくなることはないと思いtotlenます。したがって、終わりのないループが発生します。

VB.NET が C# のように動作する場合 (そして、動作すると思われます)、convert を削除するだけです。

rdlen = rdlen + len

Long+Int の結果は Long になります。ここで、Long は 64 ビットの符号付き整数で、Int は 32 ビットの符号付き整数です。

于 2011-10-01T10:24:01.537 に答える
2

これから変更してみてください:

rdlen = Convert.ToInt32(rdlen + len)

これに:

rdlen = Convert.ToInt64(rdlen + len)
于 2011-10-01T10:59:27.573 に答える