1

I have seen a lot of forums but no one has given me the solution.

I'm new to Node.Js and I'm doing an api. I want to set a JsonWebToken using RS256 algorithm. I don't have the problem with the default algorithm, so the issue really comes with the use of the RS256 algorithm.

Do I need a local SSL for this?

This the meesage error :

error:0906D06C:PEM routines:PEM_read_bio:no start line
at Sign.sign (internal/crypto/sig.js:85:26)
at Object.sign (C:\xampp\htdocs\Loctuz\server\node_modules\jwa\index.js:55:45)
at Object.jwsSign [as sign] (C:\xampp\htdocs\Loctuz\server\node_modules\jws\lib\sign-stream.js:23:24)
at Object.module.exports [as sign] (C:\xampp\htdocs\Loctuz\server\node_modules\jsonwebtoken\sign.js:189:16)
at exports.logIn (C:\xampp\htdocs\Loctuz\server\controllers\user.controller.js:22:32)
at Layer.handle [as handle_request] (C:\xampp\htdocs\Loctuz\server\node_modules\express\lib\router\layer.js:95:5)
at next (C:\xampp\htdocs\Loctuz\server\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\xampp\htdocs\Loctuz\server\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\xampp\htdocs\Loctuz\server\node_modules\express\lib\router\layer.js:95:5)
at C:\xampp\htdocs\Loctuz\server\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\xampp\htdocs\Loctuz\server\node_modules\express\lib\router\index.js:335:12)
at next (C:\xampp\htdocs\Loctuz\server\node_modules\express\lib\router\index.js:275:10)
at C:\xampp\htdocs\Loctuz\server\node_modules\body-parser\lib\read.js:130:5
at invokeCallback (C:\xampp\htdocs\Loctuz\server\node_modules\raw-body\index.js:224:16)
at done (C:\xampp\htdocs\Loctuz\server\node_modules\raw-body\index.js:213:7)
at IncomingMessage.onEnd (C:\xampp\htdocs\Loctuz\server\node_modules\raw-body\index.js:273:7)

And my code :

exports.logIn = function( req, res ){

    const RSA_PRIVATE_KEY = fs.readFileSync('./private.key');     

    const jwtBearerToken = jwt.sign({}, RSA_PRIVATE_KEY, {
        expiresIn: 120,
        algorithm: 'RS256',
        subject: "asdjjlkweqmfq12q3542211304"
    });

    res.json(jwtBearerToken);
} 

And the cosole.log(RSA_PRIVATE_KEY) :

<Buffer 7b 0d 0a 20 20 22 6b 65 79 73 22 3a 20 5b 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 22 61 6c 67 22 3a 20 22 52 53 32 35 73 73 36 22 2c 0d 0a 20 20 ... >

I'm on Windows.

  • 1
    @jps Thank you. – Boris Detry Apr 19 '18 at 09:22
  • 1
    this seems to suggest ^M in the certificate file on Windows can cause problems like this https://stackoverflow.com/questions/20837161/openssl-pem-routinespem-read-biono-start-linepem-lib-c703expecting-truste – codebrane Apr 19 '18 at 11:01

0 Answers0