jwt sign with encrypted private key and passphrase


This Content is from Stack Overflow. Question asked by Afjal

I am tring to generate jwt token with below code

const PRIVATE_KEY_PATH = join(__dirname, ‘./keys/privateob.pem’);

const jws = require(‘jws’);
const ALG = ‘PS256’;enter image description here

const privateKey = {
passphrase: ‘Passphrasehere’
const payload = {
foo: ‘bar’,

const token = jws.sign({
header: { alg: ALG },

But it showing it error
TypeError [ERR_INVALID_ARG_TYPE]: The “key.key” property must be of type string or an instance of Buffer, TypedArray, DataView, or KeyObject. Received an instance of Objectenter image description here


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?