Created
October 3, 2012 11:32
-
-
Save heapwolf/3826497 to your computer and use it in GitHub Desktop.
This file contains 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
var crypto = require('crypto'); | |
var path = require('path'); | |
var fs = require('fs'); | |
var key = fs.readFileSync(path.join(process.env['HOME'], '.ssh/foo_rsa')).toString(); | |
var pubkey = fs.readFileSync(path.join(process.env['HOME'], '.ssh/foo_rsa.pub')).toString(); | |
var data = "abcdef" | |
var sign = crypto.createSign('RSA-SHA256'); | |
sign.update(data); | |
var Sig = sign.sign(key, 'hex'); | |
var verify = crypto.createVerify('RSA-SHA256'); | |
verify.update(data); | |
console.log(verify.verify(pubkey, Sig, 'hex')); |
The problem is that the verify method always returns false.
$node --version
v0.9.0
$npm --version
1.1.44
Solution...
# generate a private key to use with your service
$openssl genrsa -out nodejitsu_rsa 1024
# create a public key to share with the service
$openssl rsa -in nodejitsu_rsa -pubout > nodejitsu_rsa.pub
var crypto = require('crypto');
var path = require('path');
var fs = require('fs');
var key = fs.readFileSync(path.join(process.env['HOME'], '.ssh/nodejitsu_rsa')).toString('ascii');
var pubkey = fs.readFileSync(path.join(process.env['HOME'], '.ssh/nodejitsu_rsa.pub')).toString('ascii');
var data = "abcdef";
var sign = crypto.createSign('SHA256');
sign.update(data);
var Sig = sign.sign(key, 'base64');
console.log(Sig);
var verify = crypto.createVerify('SHA256');
verify.update(data);
console.log(verify.verify(pubkey, Sig, 'base64'));
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$openssl genrsa -out foo_rsa 256 Generating RSA private key, 256 bit long modulus ......+++++++++++++++++++++++++++ ...+++++++++++++++++++++++++++ e is 65537 (0x10001)
$openssl rsa -in foo_rsa -pubout -out foo_rsa.pub writing RSA key