shahryarjb
Create HS256 in linux command
Hello, I need to create HS256 to save this for encryption, in this elixir I can do it with:
JOSE.JWS.generate_key(%{"alg" => "HS256"}) |> JOSE.JWK.to_map |> elem(1)
but how can I do this in linux command? because I have a shell which creates docker image for me.
I see this page but I think this page result is different with elixir code
Thanks
Most Liked
RudManusachi
from JWK Parameters for Symmetric Keys
The k (key value) member contains the value of the symmetric (or other single-valued) key. It is represented as the base64url encoding of the octet sequence containing the key value.
JOSE adds that “k” field as a random string generated by: crypto:strong_rand_bytes(Size) (In case of HS256 eventually it happens here)
you can try:
iex> {_, _, {_, key}, _} = :jose_jws_alg.generate_key({:oct, 32}, "HS256")
{:jose_jwk, :undefined,
{:jose_jwk_kty_oct,
<<228, 203, 21, 38, 196, 206, 135, 106, 22, 209, 53, 114, 53, 199, 255, 223,
52, 25, 242, 56, 5, 215, 65, 135, 13, 217, 14, 38, 235, 214, 135, 165>>},
iex> :jose_jwa_base64url.encode(key)
"5MsVJsTOh2oW0TVyNcf_3zQZ8jgF10GHDdkOJuvWh6U"
# which is basically the same as
iex> Base.url_encode64(key, padding: false)
"5MsVJsTOh2oW0TVyNcf_3zQZ8jgF10GHDdkOJuvWh6U"
So in bash probably something like
dd if=/dev/urandom bs=32 count=1 | base64 | sed 's/+/-/g; s/\//_/g; s/=//g'
Could generate you similarly random password to put into "k" field of the map
2
Popular in Questions
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
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
Other popular topics
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something…
Haskell reminds me of Java, and e...
New
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
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
- #api
- #forms
- #metaprogramming
- #security
- #hex









