Skip to content
Advertisement

PHP JWT (JSON Web Token) with RSA signature without library

Anyboby know some solution in PHP to using JWT (JSON Web Token) with RSA signature without library? I tried so hard to find solutions without library or without using composer. All the options that I found use some kind of library.

Advertisement

Answer

I made my own solution using other examples on the way. Below we have 3 use cases and the specific PHP codes to anyone that want to use:

  1. Create RSA private and public keys for sign JWT using openssl library.
  2. Create JWT token and sign using RSA private keys.
  3. Validate JWT’s signed token using RSA public keys.
  4. Example of inverted encryptation. Use public key encryptation => private key decryptation.

1 – Create RSA private and public keys for sign JWT using openssl library:

JavaScript

2 – Create JWT token and sign using RSA private keys and 3 – Validate JWT’s signed token using RSA public keys:

JavaScript

4 – Example of inverted encryptation. Use public key encryptation => private key decryptation:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement