Skip to content

Instantly share code, notes, and snippets.

@fmolliet
Last active October 30, 2021 16:12
Show Gist options
  • Select an option

  • Save fmolliet/d2fbdda87317164f6e4195f48bae16cc to your computer and use it in GitHub Desktop.

Select an option

Save fmolliet/d2fbdda87317164f6e4195f48bae16cc to your computer and use it in GitHub Desktop.
Promissified implementation of how generate key pair in nodejs
async function generateKeyPair(){
return new Promise( (resolve, reject ) => {
crypto.generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'aasas'
}
}, (err, publicKey, privateKey) => {
if( err ){
reject(err)
}
resolve({public: publicKey, private: privateKey})
});
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment