This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSP and the fly likes BASE64Encoder vs URLEncoder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "BASE64Encoder vs URLEncoder" Watch "BASE64Encoder vs URLEncoder" New topic
Author

BASE64Encoder vs URLEncoder

Tom Piersa
Greenhorn

Joined: Sep 25, 2009
Posts: 19
I’m doing AES encryption and then encoding as below. I’m then passing the encoded string on a url. Every once in a while I’m getting a + sign in my encoded string. When I pass it on the url it’s being converted to a space. What’s the difference between Base64Encoder and URLEncoder? When should I use one and not the other?

BASE64Encoder base64E = new BASE64Encoder();
String encodedStringE = base64E.encodeBuffer(encrypted);

Thanks,

Tom
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61082
    
  66

Except that they are both encodings, they are completely different.

Base64 is used to convert binary data into character data for transmission. URL encoding is used to encode URL parameter names and values.

Which you use depends on which of the above you are doing.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61082
    
  66

And yes, + is the URL encoding for a space character. If you want place data (of any type, Base64 encoded or not), on a URL, it must be URL-encoded.
Tom Piersa
Greenhorn

Joined: Sep 25, 2009
Posts: 19
Thanks for the replys. So... AES encrypts a string to a byte arrayr. If I want to pass that info to another page on the url. I should first encode it to convert the byte array to a string and then URLEncode it so I can pass it on a url? The do the reverse on the decrypt side?

Thanks much,

Tom
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61082
    
  66

I'm not sure if that's the best way to do what you are trying to do, but it should work.
Tom Piersa
Greenhorn

Joined: Sep 25, 2009
Posts: 19
It worked. I needed to do the URLEncode on the sending side. I didn't need to do anything on the receiving side.

Thanks for the help.

Tom
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BASE64Encoder vs URLEncoder