Each base64 digit represents exactly 6 bits of data. Three 8-bit bytes (i.e., a total of 24 bits) can therefore be represented by four 6-bit base64 digits. [...]'=' padding characters might be added to make the last encoded block contain four Base64 characters.
(* The TBase64DecodingStream supports two modes: * - 'strict mode': * - follows RFC3548 * - rejects any characters outside of base64 alphabet, * - only accepts up to two '=' characters at the end and * - requires the input to have a Size being a multiple of 4; otherwise raises an EBase64DecodingException * - 'MIME mode': * - follows RFC2045 * - ignores any characters outside of base64 alphabet * - takes any '=' as end of string * - handles apparently truncated input streams gracefully
I solve it by checking that it is a multiple of 4. Actually I tried and I must say that it is enough to be above 3 characters to not go wrong.