Skip to content

Instantly share code, notes, and snippets.

@mdobson
Created March 8, 2014 16:02
Show Gist options
  • Save mdobson/9434027 to your computer and use it in GitHub Desktop.
Save mdobson/9434027 to your computer and use it in GitHub Desktop.
Public Key Verification
var crypto = require('crypto');
var path = require('path');
var fs = require('fs');
var sign = crypto.createSign('RSA-SHA256');
var privateKey = path.join(__dirname, 'priv.pem');
var publicKey = path.join(__dirname, 'pub.pem');
var key = fs.readFileSync(privateKey);
var buf = sign.sign(key);
var verify = crypto.createVerify('RSA-SHA256');
var pubKey = fs.readFileSync(publicKey);
console.log(verify.verify(pubKey, buf));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment