1

I need to Base64 encode a string, but the encoded string cannot contain "+". Wikipedia mentions a modified Base64 for URL, but I can't find a .NET class which uses this.

For my application, I can't even URL encode "+" into "%2B". This is because I pass the encoded string to a service which I have no control over, and that service mangles any strings which contain "%2B". For this reason, I want my encoded string to only contain A-Z, a-z, 0-9, -, and _.

I'm aware of this having been asked before, but I don't see a working answer. Any help would be appreciated.

Community
  • 1
  • 1
royco
  • 5,409
  • 13
  • 60
  • 84
  • Sounds like the service you don't control is just storing the value for you, not unencoding it. If you're the one unencoding, you can use Base64 for URLs (or whatever you want, actually). – Harold L Dec 03 '09 at 06:49

2 Answers2

2

Can't you simply replace + and / by - and _ and vice versa when decoding?

Joey
  • 344,408
  • 85
  • 689
  • 683
  • 1
    Of course! I can't believe I didn't see this. That's what I get for coding late at night. Thanks. – royco Dec 03 '09 at 09:06
  • Hm, I'm usually better late at night than early in the morning. But showing up at noon unfortunately minimizes time I could ask coworkers :-) – Joey Dec 03 '09 at 09:11
1

Use whatever base64 encoder you have, then find and replace the '+' with whatever is appropriate (whatever your other end expects instead)

Thanatos
  • 42,585
  • 14
  • 91
  • 146