Ansvas

Ansvas

Error while decoding base64 string

Hi, I am using elixir version 1.8.2

while running in iex shell Base.decode64(“eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhenAiOiI4NDgwMzc1NTA1Mi0zYjFpNXV2b2JubnRzOWw5MzJwaGdiMmE4dWRmaHRrbi5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsImF1ZCI6Ijg0ODAzNzU1MDUyLTNiMWk1dXZvYm5udHM5bDkzMnBoZ2IyYTh1ZGZodGtuLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwic3ViIjoiMTA4MDQ0Mjc2NDQ2NzkyNDUwODk0IiwiaGQiOiJhdmlhYmlyZC5jb20iLCJlbWFpbCI6ImFuc2h1bEBhdmlhYmlyZC5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiYXRfaGFzaCI6ImlabDJ0S2JZZngwNjVtVGpQcEowT0EiLCJpYXQiOjE1NTkxNTQyNDQsImV4cCI6MTU1OTE1Nzg0NH0”)

This function return error, while it is successfully encoded on online platform like https://www.base64decode.org/

Most Liked

OvermindDL1

OvermindDL1

It shouldn’t work there either, it’s an invalid base64 encoded string, it’s the wrong length. It looks like it is missing a = at the end, so it should be:

Base.decode64("eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhenAiOiI4NDgwMzc1NTA1Mi0zYjFpNXV2b2JubnRzOWw5MzJwaGdiMmE4dWRmaHRrbi5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsImF1ZCI6Ijg0ODAzNzU1MDUyLTNiMWk1dXZvYm5udHM5bDkzMnBoZ2IyYTh1ZGZodGtuLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwic3ViIjoiMTA4MDQ0Mjc2NDQ2NzkyNDUwODk0IiwiaGQiOiJhdmlhYmlyZC5jb20iLCJlbWFpbCI6ImFuc2h1bEBhdmlhYmlyZC5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiYXRfaGFzaCI6ImlabDJ0S2JZZngwNjVtVGpQcEowT0EiLCJpYXQiOjE1NTkxNTQyNDQsImV4cCI6MTU1OTE1Nzg0NH0=")

So that website is probably just padding invalid base64 strings.

For note, you can add padding: false to Elixir’s Base.decode64/2 call to do the same automatically.

Ansvas

Ansvas

Thank you. This is working fine.

Where Next?

Popular in Discussions Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
AstonJ
If a newbie asked you about Phoenix Contexts, how would you explain the basics to them? Feel free to be as concise or in-depth as you li...
New
restack_oslo
Hello, Please pardon me for any faux paux. I am 46 and this is my first time on a forum of any kind. I wanted to to get answers from tho...
New
AstonJ
If so I (and hopefully others!) might have some tips for you :slight_smile: But first, please say which area you’re finding most challen...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
pillaiindu
I want to convert a Phoenix LiveView CRUD website to a CRUD mobile app. What do you think is the easiest way to do so?
New
arcanemachine
https://nitter.net/josevalim/status/1744395345872683471 https://twitter.com/josevalim/status/1744395345872683471
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New

We're in Beta

About us Mission Statement