Skip to content

Instantly share code, notes, and snippets.

@fmolliet
Created October 30, 2021 16:19
Show Gist options
  • Select an option

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

Select an option

Save fmolliet/626b910db9eb413e06a187a687fd18e9 to your computer and use it in GitHub Desktop.
Async implementation of public Key derivation
// 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