Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

Comparing Base64 and Base62

I need to pass data through a URL query and will first  Base64 or Base62 encode it.

I have three questions:

1. What is the difference between Base64 or Base62?
2. Do both Base64 and Base62 encode data in a way that is URL query safe?
3. Which is space efficient (Takes less bytes)?   Base64 or Base62?
SOLUTION
Avatar of Superdave
Superdave
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Marcus Bointon
Marcus Bointon
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Forgot to mention - Depending on what data you're using URL encoding can be horribly inefficient. base-64 adds a fixed and consistent 33% overhead, but URL encoding can add anywhere between 0 and 300% overhead, depending on your data. Whether this is relevant also depends if URL length is a problem - 2k is about the safe limit.
If anything is above 2k, it should not be used in any URL related activities if you ask me. Good point for the overhead.

I have a few implementations of base62 somewhere - none in java though - the only one I ever found in Java that at least was working well enough was doing it by going through Base64 and then to Base62 (and on the way back from 62 to 64 to decoded)