107 lines
2.7 KiB
Markdown
107 lines
2.7 KiB
Markdown
# TrizTech Security JWT Library
|
|
|
|
   
|
|
|
|
Internal Java library dedicated to the **generation** and **validation** of **JWT** tokens signed with **RSA (RS256)**, intended to be shared across applications within the **TrizTech** ecosystem.
|
|
|
|
---
|
|
|
|
## 1. Overview
|
|
|
|
`TrizTech Security JWT Library` is a utility Java library that allows you to:
|
|
|
|
- **generate** JWT tokens signed with **RS256**
|
|
- **validate** JWT tokens using an **RSA public key**
|
|
- **load** RSA keys from **PEM** format
|
|
|
|
---
|
|
|
|
## 2. Use Cases in the TrizTech Ecosystem
|
|
|
|
### Related Applications
|
|
|
|
- **auth-triz** — holds the **RSA private key** and generates JWT tokens
|
|
- **trizstock** — holds the **RSA public key** and validates tokens
|
|
- **trizdistribution** — holds the **RSA public key** and validates tokens
|
|
|
|
> This approach ensures that **only auth-triz can sign** tokens. The other applications can only verify them.
|
|
|
|
---
|
|
|
|
## 3. Features
|
|
|
|
- JWT generation signed with **RSA / RS256**
|
|
- JWT validation using an **RSA public key**
|
|
- Loading **private** and **public** RSA keys from PEM files
|
|
- Support for **custom claims**
|
|
- Simple API with `static` methods
|
|
- Compatible with **Java EE / Spring (non-Spring Boot)**
|
|
|
|
---
|
|
|
|
## 4. Project Structure
|
|
|
|
| Class | Role |
|
|
|--------|------|
|
|
| `JwtUtils` | JWT token generation and validation |
|
|
| `KeyLoader` | RSA key loading from PEM files |
|
|
|
|
---
|
|
|
|
## 5. Requirements
|
|
|
|
- Java 8+ (recommended: Java 17)
|
|
- JJWT 0.12.x
|
|
- Valid RSA keys in PEM format
|
|
|
|
---
|
|
|
|
## 6. Generate RSA Key Pair with OpenSSL
|
|
|
|
### 1) Generate the private key
|
|
Run this command in Terminal / Git Bash / PowerShell:
|
|
|
|
```bash
|
|
openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
|
|
```
|
|
|
|
This creates:
|
|
|
|
* private_key.pem
|
|
|
|
Example format:
|
|
```xml
|
|
-----BEGIN PRIVATE KEY-----
|
|
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBK...
|
|
-----END PRIVATE KEY-----
|
|
```
|
|
This is exactly the format your **KeyLoader.loadPrivateKey(...)** expects:
|
|
|
|
* header: -----BEGIN PRIVATE KEY-----
|
|
|
|
### 2) Generate the public key from the private key
|
|
|
|
```xml
|
|
openssl rsa -pubout -in private_key.pem -out public_key.pem
|
|
```
|
|
|
|
This creates:
|
|
|
|
* public_key.pem
|
|
|
|
Example format:
|
|
|
|
```xml
|
|
-----BEGIN PUBLIC KEY-----
|
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgK...
|
|
-----END PUBLIC KEY-----
|
|
```
|
|
|
|
This is exactly the format your **KeyLoader.loadPublicKey(...)** expects:
|
|
|
|
* header: -----BEGIN PUBLIC KEY-----
|
|
|
|
---
|
|
|
|
## 7. Auteur
|
|
Developed for the **TrizTech ecosystem** — to centralize and share JWT logic between `auth-triz`, `trizstock`, and `trizdistribution`. |