• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BASE64Encoder vs URLEncoder

 
Tom Piersa
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic