POC using pyjwt to encrypt / decrypt JWT 🔐
APACHE-2.0 License
To install the dependencies, run the following command at the repository root
:
pip install -r requirements.txt
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
You will need to create an .encrypted_file
first at the repository root
choosing the Encrypt option.
.encrypted_file
will contains a JWT containing an cryptographed data (the user machine_id).To decrypt the .encrypted_file
generated at the repository root
, choose the Decrypt option.
Note: It's also possible to check the JWT present in the .encrypted_file
content on jwt.io.
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.
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
☞ This repository uses the Apache License 2.0
☞ If you're interested in contributing to this repository, please follow the guidelines
(Criado com contributors-img)