1

UPDATE

I want to encrypt a big file (more than 180 mo for example). But I got a System.OutOfMemoryException with FlushFinalBlock().

It seems to be a valuable methods cause It "finish" encrypting my data with aditionnal bytes at the header and the footer of my stream (maybe the padding?).

Is there a way to not have this error or use an other method?

here my code:

    MemoryStream memoryStream = new MemoryStream();

    // Define cryptographic stream (always use Write mode for encryption).
    CryptoStream cryptoStream = new CryptoStream
    (
        memoryStream,
        encryptor,
        CryptoStreamMode.Write
    );

    // Start encrypting.
    cryptoStream.Write(byteArray, 0, byteArray.Length);
    // Finish encrypting.
    cryptoStream.FlushFinalBlock();
Safe
  • 313
  • 3
  • 13
  • 2
    What is the value of the `byteArray.Length` property? –  Jan 20 '17 at 14:05
  • Oh good point! My length is at 12 on my test and is at 16 on my memoryStream if I do FlushFinalBlock else it's at 0. I tested it with big files memoryStream is updated without FlushFinalBlock. – Safe Jan 20 '17 at 14:16
  • My question wasn't specific enough I will reformulate it – Safe Jan 20 '17 at 14:47
  • Don't use a memory stream, encrypt to something like a file stream and less memory will be required. – Peter Ritchie Jan 20 '17 at 17:07

0 Answers0