I'm trying to use the node.js module crypto to generate key pairs, but for some reason I cannot seem to use the generateKeyPair function.

I made sure crypto was installed and up to date, but nothing changed. Both the official docs and multiple SO answers show exactly the code I used, but don't work.

The code I used is this:

const { generateKeyPair } = require('crypto');
generateKeyPair('rsa', {
    modulusLength: 4096,
    publicKeyEncoding: {
        type: 'spki',
        format: 'pem'
    privateKeyEncoding: {
        type: 'pkcs8',
        format: 'pem',
        cipher: 'aes-256-cbc',
        passphrase: 'top secret'
}, (err, publicKey, privateKey) => {


1 Answers

Community On

Was on the wrong node version, updating to 11.x fixed it