Sunday 21 April 2019

TypeError: generateKeyPair is not a function when trying to use a function in the node.js crypto module

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) => {});

Submitted April 22, 2019 at 12:23AM by codegreen_

No comments:

Post a Comment