Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

118
Visualizações
verifying RS256 JWT in Javascript

I'm new to JWT and I'm having trouble with verifying the JWT when using the RS256 algorithm. I get error 403 every single time I try to verify the token, but I don't understand why. I'm certain I'm using the right key-files. I even tried writing : jwt.verify(publicKey, publicKey) and even with that I got error 403! Aren't they supposed to match each other exactly? What exactly is jwt.verify() doing? Is it checking if the first value is equal to the second value? Is it decoding the key?

This is how I sign the token:

 import fs from 'fs'

 const privateKey = fs.readFileSync('./private.pem', 'utf8')

 const accessToken = jwt.sign(payload, privateKey, {
        algorithm: 'RS256',
        expiresIn: '1h'
      })

And this is how I verify the token:

import createError from 'http-errors'

const authorize = (req, res, next) => {
const authorization = req.headers.authorization?.split(' ')
const publicKey = fs.readFileSync('./public.pem', 'utf8')

try {
  const payload = jwt.verify(authorization[1], publicKey)
  next()

} catch (err) {
   next(createError(403))
 }
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda