I am working with the Javascript Json Web Token library, where I create the token with the function:
var token = jwt.sign({data: 'foobar', 'secret', { expiresIn: 60 * 60 });
To verify my usage token, the function:
jwt.verify(token, 'shhhhh')
What is suggested by the library, but I want that in the field where you receive the secret
parameter, you can use some kind of certificate. The library indicates that in order to generate the token with the certificate, it is done in the following way:
var cert = fs.readFileSync('private.key');
var token = jwt.sign({ foo: 'bar' }, cert, { algorithm: 'RS256'});
To verify the token using the certificate, read a file with extension .pem
, as follows:
var cert = fs.readFileSync('public.pem');
jwt.verify(token, cert, function(err, decoded) {
console.log(decoded.foo) // bar
});
Now my question is, how do I generate those certificates that are requested in the token section? This to work with that certificate.