poc-encryption-jwt

POC using pyjwt to encrypt / decrypt JWT 🔐

APACHE-2.0 License

Stars
8

POC JWT encryption

📋 Index

🏗 Setup

To install the dependencies, run the following command at the repository root:

pip install -r requirements.txt

🚦 Usage

To execute the program, run the following command at thre repository root:

python3 main.py

It should display:

- The program started!
? What do you want to do? (Use arrow keys)
 » Encrypt
   Decrypt
  1. You will need to create an .encrypted_file first at the repository root choosing the Encrypt option.

    1. This .encrypted_file will contains a JWT containing an cryptographed data (the user machine_id).
  2. To decrypt the .encrypted_file generated at the repository root, choose the Decrypt option.

    1. The program will compare the JWT decoded machine_id with the user machine_id to check if the token is valid (Valid in that case means it has been generated on the same machine)

Note: It's also possible to check the JWT present in the .encrypted_file content on jwt.io.

⚙️ Generate new key pair

ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub

cat jwtRS256.key # private key
cat jwtRS256.key.pub # public key

The jwtRS256.key and the jwtRS256.key.pub files need to be located on the ./encryption folder.

TODOs

  • Add Unit tests.
  • Add Unit tests pipelines.

🧐 JWT Concept

References in 🇧🇷

O JWS garante através de uma assinatura digital (que usa algoritmos criptográficos) a integridade da informação que está no token, mas não garante a confidencialidade das informações. Vale lembrar que quando lidamos com tokens JWT é muito importante que a assinatura seja verificada para garantir que o conteúdo do token não tenha sido alterado.

O objetivo principal do token JWT no formato JWS é justamente permitir que os claims sejam inspecionados a fim de obter informações importantes para identificar o usuário, suas permissões e outras informações relevantes para o processo de autenticação/autorização de forma que sua sua integridade esteja garantida.

O algoritmo usado para assinar o token vai variar dependendo de como será o processo de verificação podendo ser um algoritmo simétrico (uma chave apenas) ou assimétrico (usando uma chave privada para gerar o token e uma chave pública para verificar a assinatura).

Post que resume bem alguns conceitos

By Alexandre Fidélis Vieira Bitencourt

🏅 Licensed

☞ This repository uses the Apache License 2.0

🤝 Contributing

☞ If you're interested in contributing to this repository, please follow the guidelines

Contribuidores

(Criado com contributors-img)

Badges
Extracted from project README
Security Pipeline Super Linter Gitleaks