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

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

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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
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
fayddelight
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
script
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
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
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
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
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
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
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
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement