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
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
Popular in Discussions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex










