BackendStack21 / jwt-keys-generator-api

A simple and secure JSON Web Token (JWT) signing/verification keys generator that uses OpenSSL.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JWT Keys Generator API

tests build images

A simple and secure JSON Web Token (JWT) signing/verification keys generator that uses OpenSSL.

WE DON'T DO tracking, tracing or logging of API usage!
This is an API for the community 💚

This project allows Web browser and API clients to easily generate JWT signing/verification keys supported by the jsonwebtoken library. The following algorithms are currently supported:

alg Parameter Value Digital Signature or MAC Algorithm
HS256 HMAC using SHA-256 hash algorithm
HS384 HMAC using SHA-384 hash algorithm
HS512 HMAC using SHA-512 hash algorithm
RS256 RSASSA-PKCS1-v1_5 using SHA-256 hash algorithm
RS384 RSASSA-PKCS1-v1_5 using SHA-384 hash algorithm
RS512 RSASSA-PKCS1-v1_5 using SHA-512 hash algorithm
PS256 RSASSA-PSS using SHA-256 hash algorithm (only node ^6.12.0 OR >=8.0.0)
PS384 RSASSA-PSS using SHA-384 hash algorithm (only node ^6.12.0 OR >=8.0.0)
PS512 RSASSA-PSS using SHA-512 hash algorithm (only node ^6.12.0 OR >=8.0.0)
ES256 ECDSA using P-256 curve and SHA-256 hash algorithm
ES384 ECDSA using P-384 curve and SHA-384 hash algorithm
ES512 ECDSA using P-521 curve and SHA-512 hash algorithm

See: https://github.com/auth0/node-jsonwebtoken/blob/master/README.md#algorithms-supported

Considerations:

  • For RS* and PS* algorithms, RSA keys are generated. The key size can be 1024, 2048, 3072 or 4096 bits.
  • For HS* keys, there is only private key (aka secret) and it is randomly generated using OpenSSL.
  • All keys are expected to be generated on the backend using OpenSSL to increase security.

Frontend

Backend API

  • Official URL: https://jwt-keys.21no.de/api/generate/ALGORITHM?bytes=BYTES&bits=BITS

Examples:

Parameters

bytes (optional)

For HMAC (HS*) secret keys, we need to pass the number of random bytes to be generated. Supported values: bytes >= 12 && bytes <= 160

The bytes query parameter is optional and only used for HS* algorithms. Default value is: 32

bits (optional)

See: certbot/certbot#2080

Supported values, one of: 1024, 2048, 3072, 4096

The bits query parameter is optional and only used for RS* and PS* algorithms. Default value is: 3072

Run it using Docker

Docker image is publicly available so you can run it on your own infrastructure:

docker run --rm -p 3000:3000 kyberneees/jwt-keys-generator-api:latest

Then:

curl -s http://localhost:3000/api/generate/ES512 | jq "."

Keys Generator Script

Alternatively, you can use the following script which also uses Docker:

#!/bin/bash
ALGO="${1:-RS256}"
echo "Algorihtm: $ALGO"

echo "> launching container..."
docker run -d -p 3000:3000 --name jwt-keys kyberneees/jwt-keys-generator-api > /dev/null
sleep 1

echo "> generating keys..."
curl -s http://localhost:3000/api/generate/$ALGO | jq "."

echo "> terminating container..."
docker rm --force jwt-keys > /dev/null

NOTE: Please note that only the algorithm argument is supported in the script!

Usage:

sh gen-keys.sh ES512

LICENSE

MIT License

Copyright (c) 2023 21no.de

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

A simple and secure JSON Web Token (JWT) signing/verification keys generator that uses OpenSSL.

License:MIT License


Languages

Language:JavaScript 92.9%Language:Shell 4.2%Language:Dockerfile 2.9%