I am trying to select an RSA public key stored in a database created with the node-sqlite3 library. The code implemented is the following:
const db = new sqlite3.Database('jwtauth')
db.serialize(() => {
db.each("SELECT * FROM jwtauth WHERE username = (?)", payload_data.username, (err, row) => {
const rsaPubKey = flatted.parse(row.pub)
const signature = flatted.parse(row.signature)
flag = rsaPubKey.verify(Buffer.from(JSON.stringify(payload_data)), Buffer(signature))
if (!flag) {
res.json({msg : "Failed login"})
} else {
res.json({msg : "Successful login"})
}
})
})
db.close()
THe RSA was previously created with the NodeRSA library, and then added to the database.
But I get the following error message:
Server listening on port 3000
/home/user/Desktop/project/server/node_modules/sqlite3/lib/trace.js:27
throw err;
^
TypeError: rsaPubKey.verify is not a function
at Statement.<anonymous> (/home/user/Desktop/project/server/router.js:26:30)
--> in Database#each('SELECT * FROM jwtdata WHERE username = (?)', 'john', [Function])
at Database.<anonymous> (/home/user/Desktop/project/server/router.js:23:12)
at /home/user/Desktop/project/server/router.js:21:8
at Layer.handle [as handle_request] (/home/user/Desktop/project/server/node_modules/express/lib/router/layer.js:95:5)
at next (/home/user/Desktop/project/server/node_modules/express/lib/router/route.js:144:13)
at Route.dispatch (/home/user/Desktop/project/server/node_modules/express/lib/router/route.js:114:3)
at Layer.handle [as handle_request] (/home/user/Desktop/project/server/node_modules/express/lib/router/layer.js:95:5)
at /home/user/Desktop/project/server/node_modules/express/lib/router/index.js:284:15
at Function.process_params (/home/user/Desktop/project/server/node_modules/express/lib/router/index.js:346:12)
at next (/home/user/Desktop/project/server/node_modules/express/lib/router/index.js:280:10) {
__augmented: true
}
It doesn’t recognize the RSA public key function “verify”. On the other hand, if I use that same function before inserting the RSA public key in the database, the function is recognized.
I am using node-sqlite3 version 4.2.0.