I believe this line is an error:
int bytesWritten = myTransform.TransformBlock (inputBuffer, 0, 4, transformBuffer, 0);
You convert 4 bytes, no matter how many bytes you read. I suspect you want:
int bytesWritten = myTransform.TransformBlock (inputBuffer, 0, bytesRead, transformBuffer, 0);
You may need to resize the transformBuffer , though - if you read up to 4K base64 data per iteration, you need up to 3K for plain text data per iteration.
A simpler option would probably be to create a CryptoStream using conversion, reading from the input stream, and then using Stream.CopyTo to write to FileStream .
source share