Skip to main content



      Home
Home » Language IDEs » ServerTools (WTP) » base64 decode / encode question
base64 decode / encode question [message #161227] Mon, 20 February 2006 13:00 Go to next message
Eclipse UserFriend
I have a Web Service that receives and returns a base64Binary. In order
to send the data I take a string value and convert it to base64 using the
Base64.decode() method.

In my example I have a String "Test cases" that I input into the process
(following lines of code).

Base64 b64 = new Base64();
byte[] base64 = b64.decode(txtAddItem.getText());

When I get into the Web Service I wanted to convert the base64 back into a
string using the following code.

String string64 = b64.encode(base64);

I then go to print the contents of the converted string.

System.out.println("Base 64 string: " + string64);

The output of this process looks like this "Testcase".

I am missing all the blanks and the last character is cutoff.

How do I fix this so that I get my blanks and the last character back?

Thanks,
Ben
Re: base64 decode / encode question [message #161245 is a reply to message #161227] Mon, 20 February 2006 15:13 Go to previous message
Eclipse UserFriend
Ok, have this figured out.

I need to create my Base 64 instance:

Base64 b64 = new Base64();

Then when I endcode, I need to convert from string to byte array first and
have an output of String. This was a bit confusing at first. I expected
the encoded 64 to be in byte array format and ot string so I had this
backwards.

String base64 = b64.encode(txtAddItem.getText().getBytes());

then to get back the original string I ned to decode from string base64
back to the byte array.

byte[] array64 = b64.decode(base64);

Finally I just need to convert from byte array back to string to get the
original value.

System.out.println("Base 64 string: " + new String(array64));

My Web service now receives the input to the method as a base64 in byte
array format. So, what I have to do is take the final base64 string
solution and get the byte[] value of it. My service then converts this
back to base64, and then back to String to get the original value.

I hope this helps,
Ben
Previous Topic:svn plugin
Next Topic:References search in project bug?
Goto Forum:
  


Current Time: Sat Mar 15 01:48:02 EDT 2025

Powered by FUDForum. Page generated in 0.26625 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top