AES C# File Encryption - stream writes only 16 bytes -


here piece of code, should encrypt file , write cryptograph new file. code similiar example found @ microsoft msdn webpage.

byte[] inputbuffer = new byte[inputfilestream.length]; byte[] outputbuffer = new byte[inputfilestream.length];  inputfilestream.read(inputbuffer, 0, (int)inputfilestream.length);  icryptotransform encryptor = aesinstance.createencryptor(aesinstance.key, aesinstance.iv);               using (memorystream memorystream = new memorystream())             {                  using (cryptostream stream = new cryptostream(memorystream, encryptor, cryptostreammode.write))                 {                     using (streamwriter encrypted = new streamwriter(stream))                     {                          encrypted.write(inputbuffer);                      }                      outputbuffer = memorystream.toarray();                      outputfilestream.write(outputbuffer, 0, (int)outputbuffer.length);                   }              }  outputfilestream.close(); inputfilestream.close();` 

the problem input buffer reads bytes file correct, output buffer seems have 16 bytes of data. result output file has 16 bytes, if input file large. mistake? problem exists on various modes, ecb, cbc, etc.

i believe when use

encrypted.write(inputbuffer); 

you not giving writer size of buffer write.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -