views:

247

answers:

2

The padding char for the official base64 is '=', which might need to be percent-encoded when used in a URL. I'm trying to find the best padding char so that my encoded string can be both url safe (I'll be using the encoded string as parameter value, such as id=encodedString) AND filename safe (I'll be using the encoded string directly as filename).

Dot ('.') is a popular candidate, it's url safe but it's not exactly filename safe: Windows won't allow a file name which ends with a trailing dot.

'!' seems to be a viable choice, although I googled and I've never seen anybody using it as the padding char. Any ideas? Thanks!

Update: I replaced "+" with "-" (minus) and replaced "/" with "_" (underscore) in my customized base64 encoding already, so '-' or '_' is not available for the padding char any more.

A: 

I would go with '-' or '_'
They're URL and file safe, and they looks more or less like padding

cobbal
Sorry I should have mentioned this:I replaced "+" with "-" (minus) and replaced "/" with "_" (underscore) in my customized base64 encoding already, so '-' or '_' is not available for the padding char any more.
SamS
+1  A: 

The RFC 2396 unreserved characters in URIs are:

"-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"

It's worth pointing out, though, that the Microsoft article also says "Do not assume case sensitivity." Perhaps you should just stick with base 16 or 32?

Miles
I would avoid . ~ * ' ( ) for filenames though
cobbal
Thanks Miles, seems like '!' is good for both url and file name. Maybe I'll go with base32 with '!' as the padding char.
SamS