views:

43

answers:

3

In base64 what happens if the character you want to encode isn't A-Z, a-z , + or /?

If I wanted to encode a URL in base64 which has a colon (:) in it what would happen since its not in the base64 index.

+4  A: 

You're mixing up the encode and decode sides. Base64 can encode any character. It's only decoding that requires a limited set.

Ignacio Vazquez-Abrams
More precisely, Base64 can encode any *octet*. You have to encode the characters into octets first (usually with UTF-8).
dan04
Thanks, I've gone with using the escape() function instead.
Tom
A: 

I think you're mixing things up - Base64 can encode ANYTHING, those limits simply define what the actual encoded string looks like.

So, nothing would happen if you encoded a colon in Base64. If you tried decoding a colon, however, it would most likely throw an error.

Tim Čas
+1  A: 

You can encode any byte sequence into base64. The resulting characters will all be in the allowed 64 chars. And of course when decoding the encoded text must be valid Base64.

Saying it encode any character is a bit missleading since the characters need first to be encoded into bytes. A character and a byte are only equivalent for a few charsets like ASCII.

CodeInChaos