Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

BASE64Encoder vs URLEncoder

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67528
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67528
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67528
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic