Skip to content

Instantly share code, notes, and snippets.

@zedauni
Created November 10, 2024 18:08
Show Gist options
  • Save zedauni/2b9b868bde2cbca81a59c4c6044ed67a to your computer and use it in GitHub Desktop.
Save zedauni/2b9b868bde2cbca81a59c4c6044ed67a to your computer and use it in GitHub Desktop.
Generate JWT key pair

GENERATE JWT KEY PAIR

KEEP YOUR PRIVATE KEY SECURE AND DO NOT SHARE IT PUBLICLY.

With openssl

Private Key

openssl genrsa -out private.pem 4096 # It is recommended to use a minimum of 2048

Public Key

openssl rsa -in private.pem -pubout -outform PEM -out public.pem

With ssh-keygen

Private Key

ssh-keygen -t rsa -b 4096 -m PEM -f private.pem # Add -P "" to bypass password prompt

rm private.pem.pub # Delete generated public key file

Public Key

ssh-keygen -f private.pem -e -m PKCS8 > public.pem

View generated keys content

Private Key

cat private.pem

Public Key

cat public.pem

View generated key details

Private Key

openssl rsa -text -in private.pem

Public Key

openssl rsa -pubin -text -in public.pem

Links

https://docs.mia-platform.eu/docs/runtime_suite/client-credentials/jwt_keys

https://connect2id.com/products/nimbus-jose-jwt/openssl-key-generation

https://www.cerberauth.com/blog/rsa-key-pairs-openssl-jwt-signature/

KEEP YOUR PRIVATE KEY SECURE AND DO NOT SHARE IT PUBLICLY.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment