You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
letjwt=require('jwt-simple');letpayload={foo: 'bar'};letsecret='xxx';// HS256 secrets are typically 128-bit random strings, for example hex-encoded:// let secret = Buffer.from('fe1a1915a379f3be5394b64d14794932', 'hex')// encodelettoken=jwt.encode(payload,secret);// decodeletdecoded=jwt.decode(token,secret);console.log(decoded);//=> { foo: 'bar' }
decode params
/* * jwt.decode(token, key, noVerify, algorithm) */// decode, by default the signature of the token is verifiedletdecoded=jwt.decode(token,secret);console.log(decoded);//=> { foo: 'bar' }// decode without verify the signature of the token,// be sure to KNOW WHAT ARE YOU DOING because not verify the signature// means you can't be sure that someone hasn't modified the token payloadletdecoded=jwt.decode(token,secret,true);console.log(decoded);//=> { foo: 'bar' }// decode with a specific algorithm (not using the algorithm described in the token payload)letdecoded=jwt.decode(token,secret,false,'HS256');console.log(decoded);//=> { foo: 'bar' }
Algorithms
By default the algorithm to encode is HS256.
The supported algorithms for encoding and decoding are HS256, HS384, HS512 and RS256.
// encode using HS512jwt.encode(payload,secret,'HS512')
About
JWT(JSON Web Token) encode and decode module for node.js