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
The following js code successfully generates a JWT using the algorithm HS512:
var nJwt = require('njwt');
let signingKey = "secretKey"
var claims = {
iss: 'ABCDEFGHIJ',
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + 120,
aud: 'https://appleid.apple.com',
sub: 'uk.co.myco.myApp'
}
var jwt = nJwt.create(claims,signingKey,'HS512');
var token = jwt.compact();
return token;
> took 215.16461ms
> result:
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJBQkNERUZHSElKIiwiaWF0IjoxNjg5MzMxMzMxLCJleHAiOjE2ODkzMzQ5MzEsImF1ZCI6Imh0dHBzOi8vYXBwbGVpZC5hcHBsZS5jb20iLCJzdWIiOiJ1ay5jby5teWNvLm15QXBwIiwianRpIjoiNzU3MWI0NDYtMDcwYy00Zjc2LWEyMjMtMzgxNzAyNTc4NDRlIn0.sFq2BRrCzQIJ4gqaypvk36ai2r4JCdyPXq0OxVNw2yOaJ7n1z87PpqjJUJbNkEFi1t-ydqK-mML1CiKlNcbb2g"
> result (JavaScript):
EJSON.parse('"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJBQkNERUZHSElKIiwiaWF0IjoxNjg5MzMxMzMxLCJleHAiOjE2ODkzMzQ5MzEsImF1ZCI6Imh0dHBzOi8vYXBwbGVpZC5hcHBsZS5jb20iLCJzdWIiOiJ1ay5jby5teWNvLm15QXBwIiwianRpIjoiNzU3MWI0NDYtMDcwYy00Zjc2LWEyMjMtMzgxNzAyNTc4NDRlIn0.sFq2BRrCzQIJ4gqaypvk36ai2r4JCdyPXq0OxVNw2yOaJ7n1z87PpqjJUJbNkEFi1t-ydqK-mML1CiKlNcbb2g"')
Unfortunately I need to use the ES256 algorithm. But
var nJwt = require('njwt');
let signingKey = "secretKey"
var claims = {
iss: 'ABCDEFGHIJ',
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + 120,
aud: 'https://appleid.apple.com',
sub: 'uk.co.myco.myApp'
}
var jwt = nJwt.create(claims,signingKey,'ES256');
var token = jwt.compact();
return token;
Reports an error:
> ran at 1689331442574
> took
> error:
'crypto' module: error signing message
I understand from the documentation that nJWT supports ES256. Can anyone advise the additional requirements in changing algorithms from HS512 to ES256 that I have missed?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The following js code successfully generates a JWT using the algorithm HS512:
Unfortunately I need to use the ES256 algorithm. But
Reports an error:
I understand from the documentation that nJWT supports ES256. Can anyone advise the additional requirements in changing algorithms from HS512 to ES256 that I have missed?
Beta Was this translation helpful? Give feedback.
All reactions