php - how to encrypt jwt in python without [JWT - PyJWT] modules -
i want php code :-
<? function base64encrypt($data) { return rtrim(strtr(base64_encode($data), '+/', '-_'), '='); } $header = ['alg'=>'hs256','typ'=>'jwt']; $eheaders = base64encrypt(json_encode($header)); $payload = ['sub'=>'joe']; $epayload = base64encrypt(json_encode($payload)); $secret = 'secret'; $hash = hash_hmac('sha256',"$eheaders.$epayload",$secret,true); $signature = base64encrypt($hash); $jwt = "$eheaders.$epayload.$signature"; print $jwt ; ?>
but in python not php :(
jwt - pyjwt modules doesn't work :(
from pyjwt module
code :-
import jwt print jwt.encode({'some': 'payload'}, 'secret', algorithm='hs256')
error :-
traceback (most recent call last): file "c:\users\acer\jwt.py", line 1, in import jwt file "c:\users\acer\jwt.py", line 2, in print jwt.encode({'some': 'payload'}, 'secret', algorithm='hs256') attributeerror: 'module' object has no attribute 'encode'
Comments
Post a Comment