× 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.



Hey Scott, I wrote an app in C#.Net that would encode a image to base64 using the Convert.ToBase64String Function and I used your Base64 Encode routine in an RPG/FREE web service. I found that what the .Net function returned was somewhat different than the Base64 that I borrowed from you. I tracked down what I think it is but wanted to run it by you to see if it makes sense. If you would like I would like to share what I found but it would be easier to discuss by phone. I will be in the office Monday so if you want give me a call or email offline where I could call you and a time that would be great.

But either way it is working now and I am extremely happy.

Thanks my friend.

Bruce "Hoss" Collins
Project Leader/System i Administration
AAA Cooper Transportation
(334) 671-3106



-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-
bounces@xxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: Friday, May 30, 2008 12:01 PM
To: RPG programming on the AS400 / iSeries
Subject: Re: Base64 and Microsoft

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.
--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing
list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.