× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hello Hoss,

I am using the base64 routine that Scott Klement has on his web site
and I pass the encoded data from a web services to a Microsoft C#.Net
program and I use the FromBase64String function I am getting an
"Invalid Character in Base64 String". I was reading the RFC 2045 and
my head exploded so that is why I am here. I noticed that the data
returned by Scott's routine has "=" within the data. Is this allowed.

You need to feed data into the base64_encoder() routine in multiples of 3 bytes at a time. The only time you can provide data that's not a multiple of 3 bytes is at the end of the document.

The equal signs appear in base64 encoded data when the input length was not a multiple of 3 bytes.

This isn't usually a problem. Let's say you have 1000000 (one million) bytes of data you want to encode. You don't want to encode it all at once as it's very large, so you pick a small buffer size (say, 24000 bytes, since that's a multiple of 3). So you read the first 24000, encode it, write it out. Read the next 24000, encode it, write it out, etc... after 41 passes you've read 984000 bytes, and there are only 16000 left. Now 16000 isn't a multiple of 3, but that's okay, since it's the LAST buffer that you're going to pass to base64_encode(). You're at the end of the file.

But, for some reason, your data has equal signs in the middle. That implies that, for some reason, you're encoding data that's not a multiple of three at some point in the middle of the document.

Your data also has a lot of ! characters (exclamation points) in the middle of the data, and some extra CR/LFs. ! is never a valid base64 character, and I doubt very much that this is coming from the base64_encode routine -- but I'm not sure where they're coming from. (Though, I ran into that once before with someone elses document -- it wasn't a base64 document, but long lines were split with an exclamation point. There must be some utility that does that somewhere...)

Anyway... those are the two problems I found in the data you posted:

a) Equal signs in the middle (the multiple of 3 problem)
b) extra ! and CRLF characters in the middle of the data.

Once I fixed those problems with your data, I was able to successfully decode it.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.