Project

jwk-tool

0.0
No commit activity in last 3 years
No release in over 3 years
Command line tools for operating JSON Web Key
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0

Runtime

>= 1.5.2
 Project Readme

jwk-tool

Command line tools for operating JSON Web Key

Install

gem install jwk-tool

Usage

The following command generate key pairs, private key 'key' and public key 'key.pub' into the current folder.

jwk_tool -g -k key
jwk_tool --generate --key=key

To use the keys as JSON Web Key (JSON::JWK) defined in json-jwk, just read files, parse them and then pass to the initialization method.

An encryption example at sender node using public key.

require 'json/jwt'
# read public key from file
jwk_pub = JSON::JWK.new(JSON.parse(open('key.pub').read))
# encrypt plain text "hogehogefoofoo"
jwe = JSON::JWE.new("hogehogefoofoo")
# choose block cipher algorithm
jwe.enc = :A128GCM
# choose cipher algorithm for encrypting block cipher key (symmetric cipher key)
jwe.alg = :RSA1_5
# encryption
jwe.encrypt!(jwk_pub.to_key)
# output the result in JSON format
json = jwe.as_json.to_json

A decryption example at receiver node using private key.

require 'json/jwt'
# read private key from file
jwk = JSON::JWK.new(JSON.parse(open('key').read))
# decrypt JSON format cipher data
jwe_dec = JSON::JWE.decode_json_serialized(JSON.parse(json), jwk.to_key)
# obtain the original plain text
jwe_dec.plain_text