I use the crypto core-module in node.js to generate an EC-key-pair.
I then use this key-pair to sign and verify JWT's.
I would expect the signing/verification to only work when using an EC-algorithm.
However it seems to be working with any algorithm except HMAC.
From my understanding, this shouldn't be possible.
Can anyone explain this to me?
Thank you for reading my question.
const crypto = require('crypto')
const jwt = require('jsonwebtoken')
const keyPair = crypto.generateKeyPairSync('ec', {
namedCurve: 'secp256k1',
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem'
}
})
const token = jwt.sign({}, keyPair.privateKey, {
algorithm: 'ES256' // I expect this to work, but it seems to be also working with e.g. "RS256" or "PS512", which I don't understand.
})
const verify = jwt.verify(token, keyPair.publicKey)