FromBase64String Problem

  • Thread starter Thread starter SRLoka
  • Start date Start date
S

SRLoka

I am not sure if it is a problem but, if you look at the help file, it says

Exception is thrown if :



The length of s, ignoring white space characters, is less than 4.

-or-

The length of s, ignoring white space characters, is not an even multiple of 4.
The valueless character, '=', is used for trailing padding. The end of s can consist of zero, one, or two padding characters.

What if a base64 encoded string has a length like 9, 13 (n*4 + 1), one would need to tack on 3 '='s at the end to make it a multiple of 4.
How does that work ?
Is it that a base64 string will never result in (n*4 + 1) bytes ?

Thanks
 
This is part of the specs of base 64 encoding. The string should be padded with = signs so that its length is a multiple of 4.

My guess is that the spec imposes this padding because it allows a faster implementation of the decoding algorithm. As the string is decoded by chunks of 4 characters, there is no need to test if the end has been reached in the middle of a chunk.

Bruno.
"SRLoka" <[email protected]> a écrit dans le message de I am not sure if it is a problem but, if you look at the help file, it says

Exception is thrown if :



The length of s, ignoring white space characters, is less than 4.

-or-

The length of s, ignoring white space characters, is not an even multiple of 4.
The valueless character, '=', is used for trailing padding. The end of s can consist of zero, one, or two padding characters.

What if a base64 encoded string has a length like 9, 13 (n*4 + 1), one would need to tack on 3 '='s at the end to make it a multiple of 4.
How does that work ?
Is it that a base64 string will never result in (n*4 + 1) bytes ?

Thanks
 
My question was how would I pad 3 '='s if the encoded string if needed (I have a third part tool that does not pad the '='s to save the bytes transmitted over the air) .
Well, it does not matter now because I found that a base64 encoded string will never have (multiple of 4) + 1 characters in it.

Thanks
This is part of the specs of base 64 encoding. The string should be padded with = signs so that its length is a multiple of 4.

My guess is that the spec imposes this padding because it allows a faster implementation of the decoding algorithm. As the string is decoded by chunks of 4 characters, there is no need to test if the end has been reached in the middle of a chunk.

Bruno.
"SRLoka" <[email protected]> a écrit dans le message de I am not sure if it is a problem but, if you look at the help file, it says

Exception is thrown if :



The length of s, ignoring white space characters, is less than 4.

-or-

The length of s, ignoring white space characters, is not an even multiple of 4.
The valueless character, '=', is used for trailing padding. The end of s can consist of zero, one, or two padding characters.

What if a base64 encoded string has a length like 9, 13 (n*4 + 1), one would need to tack on 3 '='s at the end to make it a multiple of 4.
How does that work ?
Is it that a base64 string will never result in (n*4 + 1) bytes ?

Thanks
 
Back
Top