Hello I am encoding a file in base 64 in c#, but for large files it doesn't work anymore.
char[] base64 = new char[miArchivo.Length];
Convert.ToBase64CharArray(miArchivo, 0, miArchivo.Length, base64, 0);
return Encoding.ASCII.GetBytes(base64);
I have tried with MemoryStream
but it has not worked, the problem is in the size of the char[] that in base64 occupies more I think.
Every 3 bytes become 4 characters, because only 7 bits of each character are used to encode information. The destination array must be at least that size.
Also note that if there are any more bytes because the size is not a multiple of 3, 4 more bytes are needed. That is, for 5 input bytes you will need 8 output, just as if they were 6.
You are missing to consider the size of the char type.
As an alternative to your code you can do: