Created
October 30, 2021 16:19
-
-
Save fmolliet/626b910db9eb413e06a187a687fd18e9 to your computer and use it in GitHub Desktop.
Async implementation of public Key derivation
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
| // Node >= v11.6.0 | |
| async function derivatePublicKey( privatePemPath ){ | |
| if (!privatePemPath) throw new Error('Pem Path not informed.') | |
| return new Promise((resolve, reject)=>{ | |
| try { | |
| const privateKey = fs.readFileSync( privatePemPath, 'utf8'); | |
| const publicKey = crypto.createPublicKey({ | |
| key: privateKey, | |
| format: 'pem' | |
| }) | |
| resolve( | |
| publicKey.export({ | |
| format: 'pem', | |
| type: 'spki' | |
| }) | |
| ); | |
| } catch (err){ | |
| reject(err) | |
| } | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment