Avatar of Molko
Molko
 asked on

Base64 Encoding / Decoding Assistance.

I have a String which has already been base64 encoded. Now when this is marshalled in weblogic is get encoded again - which i dont want, So i which to decode the orignal base64 but yet keep it in a String format.

Is this possible ?

How do i do it ?
String image   //already base64'd
    
Base64 imageBase64 = new Base64();
     
//currently
        if (image != null) {
            ImageData.setImageData(image.getBytes());
        }
 
//attempting 
 
        if (image != null) {
 
String newImage = image converted from base64 back to a String
            ImageData.setImageData(newImage.getBytes());
        }

Open in new window

Programming Languages-OtherJava

Avatar of undefined
Last Comment
CEHJ

8/22/2022 - Mon
CEHJ

>>So i which to decode the orignal base64 but yet keep it in a String format. Is this possible?

Not really - since it wouldn't need Base64 encoding if it were a real string. Why can't you decode it as byte[]
Molko

ASKER
I probably didnt explain myself propery.

The string i have is already base64 encoded, I then do ImageData.setImageData(image.getBytes()); this is then sent through Weblogic which marshalls this into another byteArray - so it get encoded again.

 When i look at this data i can see it has been encoded twice as i have used services like http://www.motobit.com/util/base64-decoder-encoder.asp to unencode and the data is the same as the original String.

If i do getByte i get a byte representation of String

Does that make sense ?
Molko

ASKER
apologies i also meant to add : given the String that has been encoded twice I can decode it via

http://www.motobit.com/util/base64-decoder-encoder.asp and then with unencoded string i can decode it again http://www.4mhz.de/b64dec.html back to binary and then view the image.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Molko

ASKER
So double encoded String -> http://www.motobit.com/util/base64-decoder-encoder.asp -> http://www.4mhz.de/b64dec.html  = .jpg

In my code i have a base64 encoded String which i can paste into this tool  http://www.4mhz.de/b64dec.html  to give me a jpg.

Currenly i have :

String image   //already base64'd

        if (image != null) {
            ImageData.setImageData(image.getBytes());
        }

So in theory i need to do a getBytes on the decoded String, i'd guess decoding the String would give me some kind of blob in with which i need to call getBytes on ....

Does that sound correct ? How do i implement this ?



Any help greatly appreciated
CEHJ

Base64 *de*coding something encoded will already give you a byte array which you can use to set the image
Molko

ASKER
Could you show me an example please ?

Thanks
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
CEHJ

Can you tell me which Base64 class you're using?
Molko

ASKER
Hi

import org.apache.commons.codec.binary.Base64;

I think I may have worked it out, just in the process of trying to prove it. The message is pushed onto a JMS queue, so I am just logging that.
ASKER CERTIFIED SOLUTION
CEHJ

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Molko

ASKER
Yeah i had something like that. Thanks

Managed to log the JMS queue as well, and it all looks good.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
CEHJ

:-)