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/f25cfeb0299c5d46b08127a5e0fcf5a4 to your computer and use it in GitHub Desktop.

Select an option

Save fmolliet/f25cfeb0299c5d46b08127a5e0fcf5a4 to your computer and use it in GitHub Desktop.
Async function for implement Sign data with private pem
async function sign(pemPath, message = '', digest = 'SHA256'){
if (!pemPath) throw new Error('Pem Path not informed.')
return new Promise((resolve, reject)=>{
try {
const privateKey = fs.readFileSync( pemPath, 'utf8');
const sign = crypto.createSign(digest)
sign.update(message)
sign.end()
resolve( sign.sign(privateKey) );
} catch (err){
reject(err)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment