You are reading a single comment by @MaBe and its replies. Click here to read the full conversation.
  • Using module hmac256 to create JSON Web Token. A PR is wating for verification and comments.

    const HMAC = require('hmac2256');
    HmacSHA256 = function(token, secret) {
          var hmac = HMAC.SHA256(E.toArrayBuffer(secret));
         return btoa(String.fromCharCode.apply(null,  hmac.digest(E.toArrayBuffer(token)))).replace(/=+$/, ''); 
    };
    
    var header = { "alg": "HS256", "typ": "JWT"};
    var data = { "id": 1337,"username": "john.doe"};
    var secret = "My very confidential secret!";
    var encodedHeader = btoa(JSON.stringify(header));
    var encodedData = btoa(JSON.stringify(data));
    var token = encodedHeader + "." + encodedData;
    var signature = HmacSHA256(token, secret);
    var jwt = (token+'.'+signature);
    
About

Avatar for MaBe @MaBe started