Last active
October 30, 2021 16:12
-
-
Save fmolliet/d2fbdda87317164f6e4195f48bae16cc to your computer and use it in GitHub Desktop.
Promissified implementation of how generate key pair in nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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