473,574 Members | 2,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert.FromBas e64String dotnet bug?

string s = "Hello";
byte[] abc = Convert.FromBas e64String(s);

This throws error
"Invalid length for a Base-64 char array."??

Does anybody have any idea about how/why this happens?

Jan 24 '07 #1
3 11221
Becase s is not a base64-encoded string.

Try Convert.ToBase6 4... instead.
"GeezerButl er" <ku******@gmail .comwrote in message
news:11******** **************@ 13g2000cwe.goog legroups.com...
string s = "Hello";
byte[] abc = Convert.FromBas e64String(s);

This throws error
"Invalid length for a Base-64 char array."??

Does anybody have any idea about how/why this happens?

Jan 24 '07 #2
GeezerButler wrote:
string s = "Hello";
byte[] abc = Convert.FromBas e64String(s);

This throws error
"Invalid length for a Base-64 char array."??

Does anybody have any idea about how/why this happens?
Put cursor in FromBase64Strin g. Hit F1. Help page says:

The length of s, ignoring white space characters, is not zero or a
multiple of 4.
What are you actually trying to do?

Larry Lard
la*******@googl email.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Jan 25 '07 #3
GeezerButler <ku******@gmail .comwrote:
string s = "Hello";
byte[] abc = Convert.FromBas e64String(s);

This throws error
"Invalid length for a Base-64 char array."??

Does anybody have any idea about how/why this happens?
Yes - it's like saving a file with the word "Hello" in and then opening
it up in Paintshop Pro as if it were a JPEG: "Hello" is not a valid
Base64-encoded lump of data.

Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 25 '07 #4

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

Similar topics

by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use System.Text.UnicodeEncoding enc = new System.Text.UnicodeEncoding(); now i am using enc.GetString(value) and the value retured is one byte less if the size of the byte...
by: Dan | last post by:
I need to convert a byte array to a string in order to upload a binary file with an httpWebRequest. What's the most efficient way to do such a conversion?
by: Shankar | last post by:
How can we convert the integer values to byte arrays using C#.NET
by: fabrice | last post by:
Hello I'm getting an error during a .vb file compilation. My command is : vbc /t:library /r:system.web.dll /r:system.dll /r:mscorlib.dll myFile.vb The error is :
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 the Convert.FromBase64String function but get the following error. Invalid length for a Base-64 char array The same code works ok if I call...
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 a firewall. I've used the .NET Convert.ToBase64String() method to encode the data. I understand that the Convert.FromBase64String only runs on...
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 get the new connection string from plain text to the encrypted string as is currently used?
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 "Invalid character in Base-64 string." My code is like this. XmlTextReader xmlReader = new XmlTextReader(XML_LAYOUT_FILE_PATH); ...
by: Bob Altman | last post by:
Hi all, I'm looking for the fastest way to convert an array of bytes to String. I also need to convert a String back to its original Byte() representation. Convert.ToBase64String and Convert.FromBase64String seem like the closest thing I can find to what I'm looking for baked into the base class library. Can anyone suggest a better way...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.