473,407 Members | 2,306 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,407 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 5472
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.