Using Rijndael encryption for large files

后端 未结 3 2103
忘掉有多难
忘掉有多难 2021-02-09 06:47

I\'m in a situation where I need to encrypt / decrypt a file of n length securely, ideally using Rijndael, but definitely at 256bit encryption.

I\'ve played around with

3条回答
  •  甜味超标
    2021-02-09 07:07

    The Stream.Read method, returns the number of bytes actually being read from the stream.

    You should use this return value as the last parameter in the Write method on the next line.

    My code would look like this:

    byte[] chunkData = new byte[chunkSize];   
    var bytesRead = 0;
    while ((bytesRead = fsInput.Read(chunkData, 0, chunkSize)) > 0)
    {
        cryptoStream.Write(chunkData, 0, bytesRead);
    }
    

提交回复
热议问题