This guide will help you generate RSA keys and create a JSON Web Key Set (JWKS).
ALTERNATIVE -- build file on https://pem2jwk.vercel.app/
Run the following command to generate an RSA private key:
openssl genpkey -algorithm RSA -out private-key.pem -pkeyopt rsa_keygen_bits:2048This command will create a private-key.pem file with a 2048-bit RSA private key.
Now, generate the corresponding public key from the private key by running:
openssl rsa -in private-key.pem -pubout -out public-key.pemThis will create a public-key.pem file containing the public key.
Next, export the modulus from the public key:
openssl rsa -pubin -in public-key.pem -modulus -nooutecho -n "MODULUS_STRING" | xxd -r -p | base64 | tr '+/' '-_' | tr -d '='{
"keys": [
{
"kty": "RSA",
"kid": "unique-key-id",
"use": "sig",
"n": "BASE64_URL_MODULUS",
"e": "BASE64_URL_EXPONENT"
}
]
}