hoseinisalim
Convert base64 string to byte string
how to convert base64 string to byte string?
Most Liked
chrismcg
You can turn it into a list:
iex(11)> "Like this š" |> Base.encode64
"TGlrZSB0aGlzIPCfmIA="
iex(12)> "TGlrZSB0aGlzIPCfmIA=" |> Base.decode64!() |> :binary.bin_to_list()
[76, 105, 107, 101, 32, 116, 104, 105, 115, 32, 240, 159, 152, 128]
2
NobbZ
I already told you a few times, the documentation of that library is far from par.
Also @chrismcg told you to try Base.url_decode64!/1, which you obviously didnāt, as it works for me:
iex(1)> message = "Foo"
"Foo"
iex(2)> {:ok, key64} = ExCrypto.generate_aes_key(:aes_256, :base64)
{:ok, "YBFgCMzhnxIOVeirWf5hgzbFmUcvZcHY0yKRJJ4Ocks="}
iex(3)> key = Base.url_decode64!(key64)
<<96, 17, 96, 8, 204, 225, 159, 18, 14, 85, 232, 171, 89, 254, 97, 131, 54, 197,
153, 71, 47, 101, 193, 216, 211, 34, 145, 36, 158, 14, 114, 75>>
iex(4)> {:ok, {iv, ciphered}} = ExCrypto.encrypt(key, message)
{:ok,
{<<195, 207, 172, 38, 128, 248, 158, 10, 14, 239, 231, 195, 48, 154, 244, 177>>,
<<4, 238, 11, 86, 7, 6, 5, 86, 13, 182, 189, 113, 193, 85, 194, 141>>}}
iex(5)> {:ok, clear} = ExCrypto.decrypt(key, iv, ciphered)
{:ok, "Foo"}
It seems as if you really need to actively read and understand the sources of this library to be able to use it.
My suggestion is, that you use :bytes with the key generator and then convert the resulting binary to exactly the format you really need. No surprises anymore because of bad documentation, that claims to return base64 encoded string but actually does return an Base64-URL-encoded stringā¦
2
Popular in Questions
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Hi all,
Iāve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
Iām trying to use Postgres...
New
If I have a string ā1000 cfu/mlā . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
Iām not a pro in using Regex and canāt figure out why the following behaviour happens, especially if we take into account the difference ...
New
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
Hi,
is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Other popular topics
Hi!
In PHP: $_SERVER[āSERVER_ADDRā] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
Hi everyone,
One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Hi guys, iām new in the Elixir world, and i have to say, that i love it!
iām having some problem to understand anonymous functions with ...
New
Original source of discussion: This topic on the Pragmatic Programmersā Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
I would like to know what is the best IDE for elixir development?
New
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo ā Ecto v3.14.0 has exampl...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
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










