Generating a JSON Web Key (JWK) With Ruby

Featured image for sharing metadata for article

Sometimes you need to generate a new JWK, and converting an existing key isn't quite what you want.

We can use the ruby-jose library to do this via its handy generate_key method, which provides us a JWKS when invoking the script:

require 'jose'
jwk = JOSE::JWS.generate_key({"alg" => "RS256"})
jwk_s = JSON.parse(jwk.to_binary)
puts JSON.pretty_generate(keys: jwk_s)

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #pki #ruby #pem #jwks.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.