How to create a privateKey/publicKey pair of KeyObject return type and 256 bits length in Node.js? Kindly ask you to provide a working example. I tried this one:
const { generateKeyPair } = require('node:crypto');
generateKeyPair(
'rsa',
{
modulusLength: 1024,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: secret
}
},
(err, publicKey, privateKey) => {
if (err) res.end(JSON.stringify(err));
console.log('private: ', privateKey);
console.log('public: ', publicKey);
}
);
But when I change modulusLength value to the required 256 bits I get an error. I need it for JOSE JWE secret.