Created
January 23, 2017 14:36
Revisions
-
MatthieuLemoine created this gist
Jan 23, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ const id = '__JUNK__'; // Public key need to be in PKCS8 format // ssh-keygen -e -m PKCS8 -f id_rsa.pub > id_rsa.pkcs8 const publicKey = fs.readFileSync(path.join(__dirname, 'id_rsa.pkcs8'), { encoding : 'utf8' }); const privateKey = fs.readFileSync(path.join(__dirname, 'id_rsa'), { encoding : 'utf8' }); // Sign const signer = crypto.createSign('RSA-SHA512'); signer.update(id); const signature = signer.sign(privateKey, 'hex'); // ... // Verify const verifier = crypto.createVerify('RSA-SHA512'); verifier.update(ruid); const publicKeyBuf = new Buffer(publicKey, 'utf-8'); const signatureBuf = new Buffer(signature, 'hex'); const result = verifier.verify(publicKeyBuf, signatureBuf);