wood burning stoves 2.0*
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
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: 60780
    
  65

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: 60780
    
  65

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: 60780
    
  65

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
 
jQuery in Action, 2nd edition
 
subject: BASE64Encoder vs URLEncoder
 
Similar Threads
%20f problem
XML in the URL
BASE64Encoder
getParameter () method of HttpServletRequest
Problems passing '%' and '&' as params in jsp:include