Skip to content

Instantly share code, notes, and snippets.

@omarkj
Created September 16, 2010 16:38
Show Gist options
  • Save omarkj/582723 to your computer and use it in GitHub Desktop.
Save omarkj/582723 to your computer and use it in GitHub Desktop.
var fs = require('fs'),
assert = require('assert'),
crypto = require('crypto');
var msg = "Gaur!";
fs.readFile('PrivateKey.pem', 'utf-8', function(e,pri) {
var signer = crypto.createSign('sha256').update(msg);
var signature = signer.sign(pri, output_format='base64');
fs.readFile('PublicKey.pem', 'utf-8', function(e,pub) {
var verifier = crypto.createVerify('sha256').update(msg);
var verified = verifier.verify(pub, signature, signature_format='base64');
assert.equal(verified, 1)
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment