Last active
October 30, 2021 16:12
-
-
Save fmolliet/f25cfeb0299c5d46b08127a5e0fcf5a4 to your computer and use it in GitHub Desktop.
Async function for implement Sign data with private pem
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 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