473,387 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

FromBase64String Problem

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

-----------------

Srinivas Loka

Nov 16 '05 #1
3 5469
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" <ls******@hotmail.com> a écrit dans le message de news:Oc****************@TK2MSFTNGP09.phx.gbl...
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

-----------------

Srinivas Loka

Nov 16 '05 #2
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" <ls******@hotmail.com> a écrit dans le message de news:Oc****************@TK2MSFTNGP09.phx.gbl...
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

-----------------

Srinivas Loka

Nov 16 '05 #3
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
"Bruno Jouhier [MVP]" <bj******@club-internet.fr> wrote in message news:eN**************@TK2MSFTNGP09.phx.gbl...
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" <ls******@hotmail.com> a écrit dans le message de news:Oc****************@TK2MSFTNGP09.phx.gbl...
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

-----------------

Srinivas Loka

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
0
by: SRLoka | last post by:
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-
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
5
by: scottrm | last post by:
I have a asp.net web service built in c# which is accepting a string parameter from a vb6 client. The string parameter contains some xml. I am attempting to convert the string to a byte array using...
0
by: Andy | last post by:
Hi, I have a MS Word binary data file that is sent from my .NET webservice in response to an XMLHTTP request from an Internet Explorer client. This data has to be base64 encoded to tunnel through...
3
by: GeezerButler | last post by:
string s = "Hello"; byte abc = Convert.FromBase64String(s); This throws error "Invalid length for a Base-64 char array."?? Does anybody have any idea about how/why this happens?
3
by: Steve | last post by:
I took over a web app that the developer encrypted the connection string. The connection string looks something like this )); Now, I need to change the string in the web config file, so how can I...
0
by: BobbyS | last post by:
I've a xml file.I'm taking its data passing it to a method in string form and converting that string "xmlData" to a array of bytes by Convert.FromBase64String(xmlData) but I'm getting a exception...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.