Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. const id = '__JUNK__';
  2. // Public key need to be in PKCS8 format
  3. // ssh-keygen -e -m PKCS8 -f id_rsa.pub > id_rsa.pkcs8
  4. const publicKey = fs.readFileSync(path.join(__dirname, 'id_rsa.pkcs8'), { encoding : 'utf8' });
  5. const privateKey = fs.readFileSync(path.join(__dirname, 'id_rsa'), { encoding : 'utf8' });
  6.  
  7. // Sign
  8. const signer = crypto.createSign('RSA-SHA512');
  9. signer.update(id);
  10. const signature = signer.sign(privateKey, 'hex');
  11.  
  12. // ...
  13.  
  14. // Verify
  15. const verifier = crypto.createVerify('RSA-SHA512');
  16. verifier.update(ruid);
  17. const publicKeyBuf = new Buffer(publicKey, 'utf-8');
  18. const signatureBuf = new Buffer(signature, 'hex');
  19. const result = verifier.verify(publicKeyBuf, signatureBuf);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement