# Support for urlsafe alphabets in Base64?

**URL:** <https://discourse.julialang.org/t/support-for-urlsafe-alphabets-in-base64/4065>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [June 2, 2017, 7:57pm UTC](https://discourse.julialang.org/t/support-for-urlsafe-alphabets-in-base64/4065 "2017-06-02T19:57:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![krm01](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krm01/32/3051_2.png) [@krm01](https://discourse.julialang.org/u/krm01)\
**Post date:** [June 2, 2017, 7:57pm UTC](https://discourse.julialang.org/t/support-for-urlsafe-alphabets-in-base64/4065/1 "2017-06-02T19:57:11Z")

</div>

the Base64 module seems to be hardcoded to use the standard alphabet - I need to consume data encoded with the urlsafe alphabet (`-`,`_` instead of `+`,`/`). As a workaround I’m translating the source string into the urlsafe equivalent before decoding, like

```julia
base64decode(replace(replace(str, "-", "+"), "_", "/"))

```

but this feels pretty dirty, and obviously impractical for arbitrary alphabets. I think there’s value in separating the base64 encoding/decoding routines from the alphabet they use, allowing convenience functions

```julia
urlsafebase64decode(str)

```

or the generic case

```julia
base64decode(str, alphabet=myAlphabet)

```

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [June 3, 2017, 3:11am UTC](https://discourse.julialang.org/t/support-for-urlsafe-alphabets-in-base64/4065/2 "2017-06-03T03:11:11Z")

</div>

I ended up writing my own base64 encode/decode methods, for this exact reason.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [June 14, 2017, 7:31pm UTC](https://discourse.julialang.org/t/support-for-urlsafe-alphabets-in-base64/4065/3 "2017-06-14T19:31:24Z")

</div>

You could make a PR allowing different alphabets to be specified.

---

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [March 26, 2023, 5:11pm UTC](https://discourse.julialang.org/t/support-for-urlsafe-alphabets-in-base64/4065/4 "2023-03-26T17:11:10Z")

</div>

I am running into the same issue after 6 years - you mentioned you created your own encode/decode methods for this reason - can you share them?

I am looking for the decode version and don’t like to make any mistake in the implementation
