shahryarjb

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 Responses

RudManusachi

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

kip

kip

ex_cldr Core Team

I suggest this would appear to be doing what you ask using using openssl.

Where Next?

Popular in Questions Top

chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
gshaw
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
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
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
shahryarjb
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
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
fireproofsocks
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
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
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
shijith.k
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
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

We're in Beta

About us Mission Statement