Skip to content

Instantly share code, notes, and snippets.

@adolfont
Forked from carlosbrando/gist:995982
Last active November 6, 2020 20:27
Show Gist options
  • Save adolfont/97d1fbf154500650c9d96add8129f15c to your computer and use it in GitHub Desktop.
Save adolfont/97d1fbf154500650c9d96add8129f15c to your computer and use it in GitHub Desktop.
Erlang Base64
-module (base64ex).
-export ([urlsafe_decode64/1, urlsafe_encode64/1]).
urlsafe_decode64(Str) ->
Str2 = re:replace(Str, "-", "+", [global, {return,list}]),
Str3 = re:replace(Str2, "_", "/", [global, {return,list}]),
base64:decode(Str3).
urlsafe_encode64(Bin) ->
Bin2 = base64:encode(Bin),
Bin3 = re:replace(binary_to_list(Bin2), "\\+", "-", [global, {return,list}]),
re:replace(Bin3, "/", "_", [global, {return,list}]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment